mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
test expectations for IDEA-92380 "Constant Conditions & Exceptions": relax possible NPE reporting for fields
This commit is contained in:
+68
@@ -0,0 +1,68 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Foo {
|
||||
Object data;
|
||||
|
||||
void checkNotNullAndUse(Foo f) {
|
||||
if (f.data != null) {
|
||||
System.out.println(f.data.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
void checkNullAndReturn(Foo f) {
|
||||
if (f.data == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(f.data.hashCode());
|
||||
}
|
||||
|
||||
void warnWhenWrongCheck() {
|
||||
if (data != null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(<warning descr="Method invocation 'data.hashCode()' may produce 'java.lang.NullPointerException'">data.hashCode()</warning>);
|
||||
System.out.println(data.hashCode());
|
||||
}
|
||||
|
||||
void dontWarnWhenNotChecked(Foo f) {
|
||||
System.out.println(f.data.hashCode());
|
||||
}
|
||||
|
||||
void dontWarnWhenNotCheckedThis() {
|
||||
System.out.println(data.hashCode());
|
||||
}
|
||||
|
||||
void dontWarnWhenDoubleChecked(Foo f) {
|
||||
if (f.data == null) {
|
||||
return;
|
||||
}
|
||||
if (f.data == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(f.data.hashCode());
|
||||
}
|
||||
|
||||
void dontWarnWhenDoubleChecked_This_Synchronized() {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println(data.hashCode());
|
||||
}
|
||||
|
||||
void dontWarnWhenDoubleChecked_This_WithMethodCall() {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(data.hashCode());
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(data.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Foo {
|
||||
@Nullable Object data;
|
||||
|
||||
void checkNotNullAndUse(Foo f) {
|
||||
if (f.data != null) {
|
||||
System.out.println(f.data.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
void checkNullAndReturn(Foo f) {
|
||||
if (f.data == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(f.data.hashCode());
|
||||
}
|
||||
|
||||
void warnWhenWrongCheck() {
|
||||
if (data != null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(<warning descr="Method invocation 'data.hashCode()' may produce 'java.lang.NullPointerException'">data.hashCode()</warning>);
|
||||
System.out.println(data.hashCode());
|
||||
}
|
||||
|
||||
void warnWhenNotCheckedOnce(Foo f) {
|
||||
System.out.println(<warning descr="Method invocation 'f.data.hashCode()' may produce 'java.lang.NullPointerException'">f.data.hashCode()</warning>);
|
||||
System.out.println(f.data.hashCode());
|
||||
}
|
||||
|
||||
void warnWhenNotCheckedThisOnce() {
|
||||
System.out.println(<warning descr="Method invocation 'data.hashCode()' may produce 'java.lang.NullPointerException'">data.hashCode()</warning>);
|
||||
System.out.println(data.hashCode());
|
||||
}
|
||||
|
||||
void dontWarnWhenDoubleChecked(Foo f) {
|
||||
if (f.data == null) {
|
||||
return;
|
||||
}
|
||||
if (f.data == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(f.data.hashCode());
|
||||
}
|
||||
|
||||
void dontWarnWhenDoubleChecked_This_Synchronized() {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println(data.hashCode());
|
||||
}
|
||||
|
||||
void dontWarnWhenDoubleChecked_This_WithMethodCall() {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(data.hashCode());
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(data.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -131,5 +131,8 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
|
||||
}
|
||||
|
||||
public void testConstantDoubleComparisons() { doTest(); }
|
||||
|
||||
public void _testMutableNullableFieldsTreatment() { doTest(); }
|
||||
public void testMutableNotAnnotatedFieldsTreatment() { doTest(); }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user