blob: 98c26df45721d9db5c4f0b4d07fe8955ff879a6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
class Bar3 {
@NotNull
Object getObj() {
return new Object();
}
void foo(Collection<Object> collection) {
if (!collection.isEmpty()) {
Object first = collection.iterator().next();
if (first != getObj() || collection.size() > 0) {
System.out.println(first.hashCode());
}
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>);
}
}
}
}
|