Skip to content

Instantly share code, notes, and snippets.

@occho
Created June 24, 2015 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save occho/276b7ac111f63d70888f to your computer and use it in GitHub Desktop.
Save occho/276b7ac111f63d70888f to your computer and use it in GitHub Desktop.
NULL_DEREFERENCE and RESOURCE_LEAK
import java.io.IOException;
import java.io.FileOutputStream;
class Hello {
int testInfer_NPE() {
String s = null;
return s.length();
}
void testInfer_notClose() throws IOException {
FileOutputStream s = new FileOutputStream("output.txt");
s.write(48);
}
}
/Users/JP20353/proj/infer/Hello.java:6: error: NULL_DEREFERENCE
object s last assigned on line 5 could be null and is dereferenced at line 6
/Users/JP20353/proj/infer/Hello.java:11: error: RESOURCE_LEAK
resource acquired to s by call to FileOutputStream(...) at line 10 is not released after line 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment