You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

/*
* Copyright (c) 2013 - 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 endtoend.java.eradicate;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class ParameterNotNullableTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/eradicate/ParameterNotNullable.java";
public static final String PARAMETER_NOT_NULLABLE =
"ERADICATE_PARAMETER_NOT_NULLABLE";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults =
InferResults.loadEradicateResults(ParameterNotNullableTest.class, SOURCE_FILE);
}
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {
"callNull",
"callNullable",
"testSystemGetPropertyArgument",
Add model of java.lang.Class.getResource Summary: public It is possible to return null according to http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource(java.lang.String). Also, getResource throws NPE if passed null: $ cat -n TestClassGetResourceArgument.java 1 import java.net.URL; 2 3 public class TestClassGetResourceArgument { 4 5 static URL testClassGetResourceArgument(Class cls) { 6 return cls.getResource(null); 7 } 8 9 public static void main(String[] args) { 10 System.out.println(testClassGetResourceArgument("".getClass()).toString()); 11 } 12 13 } $ javac TestClassGetResourceArgument.java && java TestClassGetResourceArgument Exception in thread "main" java.lang.NullPointerException at sun.misc.MetaIndex.mayContain(MetaIndex.java:243) at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:830) at sun.misc.URLClassPath.getResource(URLClassPath.java:199) at sun.misc.URLClassPath.getResource(URLClassPath.java:251) at java.lang.ClassLoader.getBootstrapResource(ClassLoader.java:1305) at java.lang.ClassLoader.getResource(ClassLoader.java:1144) at java.lang.ClassLoader.getResource(ClassLoader.java:1142) at java.lang.ClassLoader.getSystemResource(ClassLoader.java:1267) at java.lang.Class.getResource(Class.java:2145) at TestClassGetResourceArgument.testClassGetResourceArgument(TestClassGetResourceArgument.java:6) at TestClassGetResourceArgument.main(TestClassGetResourceArgument.java:10) Reviewed By: cristianoc Differential Revision: D2752301 fb-gh-sync-id: 888baf1
9 years ago
"testClassGetResourceArgument",
};
assertThat(
"Results should contain " + PARAMETER_NOT_NULLABLE,
inferResults,
containsExactly(
PARAMETER_NOT_NULLABLE,
SOURCE_FILE,
methods));
}
}