Summary: This deteriorated over time. Reviewed By: dulmarod Differential Revision: D5406274 fbshipit-source-id: 286f122master
parent
6bbb186ce2
commit
9a2746c143
@ -0,0 +1,17 @@
|
||||
# Copyright (c) 2017 - present Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
SOURCES = Resources.java Pointers.java Hello.java
|
||||
OBJECTS = $(SOURCES:.java=.class)
|
||||
|
||||
all: Hello.class
|
||||
|
||||
%.class: $(SOURCES)
|
||||
javac $(SOURCES)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJECTS)
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package hello;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Random;
|
||||
|
||||
class Hello {
|
||||
|
||||
void doesNotCauseNPE() {
|
||||
Pointers.A a = Pointers.mayReturnNull(10);
|
||||
a.method();
|
||||
}
|
||||
|
||||
void mayCauseNPE() {
|
||||
Random rng = new Random();
|
||||
Pointers.A a = Pointers.mayReturnNull(rng.nextInt());
|
||||
// NPE
|
||||
a.method();
|
||||
}
|
||||
|
||||
void mayLeakResource() throws IOException {
|
||||
OutputStream stream = Resources.allocateResource();
|
||||
if (stream == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
stream.write(12);
|
||||
} finally {
|
||||
// Resource leak
|
||||
}
|
||||
}
|
||||
|
||||
void twoResources() throws IOException {
|
||||
FileInputStream fis = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fis = new FileInputStream(new File("whatever.txt"));
|
||||
fos = new FileOutputStream(new File("everwhat.txt"));
|
||||
fos.write(fis.read());
|
||||
} finally {
|
||||
if (fis != null) { fis.close(); } // Resource leak
|
||||
if (fos != null) { fos.close(); }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package hello;
|
||||
|
||||
public class Pointers {
|
||||
|
||||
public static class A {
|
||||
public void method() {
|
||||
}
|
||||
}
|
||||
|
||||
public static A mayReturnNull(int i) {
|
||||
if (i > 0) {
|
||||
return new A();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package hello;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Resources {
|
||||
|
||||
public static FileOutputStream allocateResource() {
|
||||
try {
|
||||
File file = new File("foo.txt");
|
||||
return new FileOutputStream(file);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1 +1,4 @@
|
||||
build_systems/codetoanalyze/make/Hello.java, void Hello.mayCauseNPE(), 4, NULL_DEREFERENCE, [start of procedure mayCauseNPE(),Skipped call: function or method not found,start of procedure mayReturnNull(...),Taking false branch,return from a call to Pointers$A Pointers.mayReturnNull(int)]
|
||||
build_systems/codetoanalyze/make/Hello.java, void Hello.mayLeakResource(), 7, RESOURCE_LEAK, [start of procedure mayLeakResource(),start of procedure allocateResource(),Skipped call: function or method not found,return from a call to FileOutputStream Resources.allocateResource(),Taking false branch]
|
||||
build_systems/codetoanalyze/make/Hello.java, void Hello.twoResources(), 11, RESOURCE_LEAK, [start of procedure twoResources(),Taking true branch,exception java.io.IOException]
|
||||
build_systems/codetoanalyze/make/utf8_in_function_names.c, test_성공, 2, NULL_DEREFERENCE, [start of procedure test_성공()]
|
||||
|
@ -1 +1,4 @@
|
||||
Hello.java, void Hello.mayCauseNPE(), 4, NULL_DEREFERENCE, [start of procedure mayCauseNPE(),Skipped call: function or method not found,start of procedure mayReturnNull(...),Taking false branch,return from a call to Pointers$A Pointers.mayReturnNull(int)]
|
||||
Hello.java, void Hello.mayLeakResource(), 7, RESOURCE_LEAK, [start of procedure mayLeakResource(),start of procedure allocateResource(),Skipped call: function or method not found,return from a call to FileOutputStream Resources.allocateResource(),Taking false branch]
|
||||
Hello.java, void Hello.twoResources(), 11, RESOURCE_LEAK, [start of procedure twoResources(),Taking true branch,exception java.io.IOException]
|
||||
utf8_in_function_names.c, test_성공, 2, NULL_DEREFERENCE, [start of procedure test_성공()]
|
||||
|
Loading…
Reference in new issue