dfa: a variable can't be null after dereference (IDEA-122215)

This commit is contained in:
peter
2014-03-28 19:12:00 +01:00
parent 87a2944e37
commit 6d2412b599
4 changed files with 46 additions and 5 deletions
@@ -18,6 +18,27 @@ class Bar3 {
if (first == getObj() || collection.size() > 0) {
System.out.println(first.hashCode());
}
if (<warning descr="Condition 'first == null' is always 'false'">first == null</warning>) {
System.out.println(first.hashCode());
}
}
}
void foo2(Collection<Object> collection) {
if (!collection.isEmpty()) {
Object first = collection.iterator().next();
if (first != getObj() || collection.size() > 0) {
first.hashCode();
}
}
}
void foo3(Collection<Object> collection) {
if (!collection.isEmpty()) {
Object first = collection.iterator().next();
if (first == getObj() || collection.size() > 2) {
System.out.println(first.hashCode());
}
if (first == null) {
System.out.println(<warning descr="Method invocation 'first.hashCode()' may produce 'java.lang.NullPointerException'">first.hashCode()</warning>);
}
@@ -0,0 +1,9 @@
class Foo {
private void someMethod(String someArg) {
someArg.getClass();
if (<warning descr="Condition 'someArg == null' is always 'false'">someArg == null</warning>) {
System.err.println("Wrong argument");
}
}
}