dfa: assume fields used before initialization are null (IDEA-110297)

This commit is contained in:
peter
2017-02-08 16:10:57 +01:00
parent 3d33fe9b17
commit 0906b83847
4 changed files with 32 additions and 1 deletions
@@ -0,0 +1,14 @@
class Foo {
String field;
String field2 = field.<warning descr="Method invocation 'substring' may produce 'java.lang.NullPointerException'">substring</warning>(1);
int field3 = field2.length();
Runnable r = new Runnable() {
public void run() {
System.out.println(field.hashCode());
}
};
Foo() {
field = "x";
}
}
@@ -1,7 +1,7 @@
class Foo {
String field;
String field2;
int hash = field.hashCode();
int hash = field.<warning descr="Method invocation 'hashCode' may produce 'java.lang.NullPointerException'">hashCode</warning>();
Foo(String f2) {
field2 = f2;
@@ -421,6 +421,8 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testDivisionByZero() { doTestReportConstantReferences(); }
public void testFieldUsedBeforeInitialization() { doTest(); }
public void testImplicitlyInitializedField() {
PlatformTestUtil.registerExtension(ImplicitUsageProvider.EP_NAME, new ImplicitUsageProvider() {
@Override