Java: Document two FPs with unit tests.

This commit is contained in:
Anders Schack-Mulligen
2020-01-17 09:57:11 +01:00
parent f7278d36e1
commit 2dca188288
2 changed files with 42 additions and 0 deletions

View File

@@ -168,4 +168,44 @@ public class C {
finalObj.hashCode(); // OK
}
}
private void verifyBool(boolean b) {
if (!b) {
throw new Exception();
}
}
public void ex13(int[] a) {
int i = 0;
boolean b = false;
Object obj = null;
while (a[++i] != 0) {
if (a[i] == 1) {
obj = new Object();
b = true;
} else if (a[i] == 2) {
verifyBool(b);
obj.hashCode(); // NPE - false positive
}
}
}
private void verifyNotNull(Object obj) {
if (obj == null) {
throw new Exception();
}
}
public void ex14(int[] a) {
int i = 0;
Object obj = null;
while (a[++i] != 0) {
if (a[i] == 1) {
obj = new Object();
} else if (a[i] == 2) {
verifyNotNull(obj);
obj.hashCode(); // NPE - false positive
}
}
}
}