View Javadoc
1   package nullnessAnnotations;
2   
3   import javax.annotation.CheckForNull;
4   import javax.annotation.Nonnull;
5   
6   public class UseAnnotations {
7   	
8   	@CheckForNull Object f(int x) {
9   		if (x == 0) return null;
10  		return (Integer) x;
11  	}
12  	
13  	int g(@Nonnull Object x) {
14  		return 42;
15  	}
16  	int foo() {
17  		return g(f(12));  // should generate a warning here (but don't)
18  	}
19  	int foo2() {
20  		return g(null);  // should and do generate a warning here
21  	}
22  	int foo3(int x) {
23  		Object y = null;
24  		if (x > 0) y = "";
25  		return g(y);  // should generate a warning here (but don't)
26  	}
27  	int foo4() {
28  		return f(12).hashCode();  // should generate a warning here (but don't)
29  	}
30  
31  	int bar() {
32  		return f(12).hashCode();  // should generate a warning here (but don't)
33  	}
34  	int bar2() {
35  		Object x = null;
36  		return x.hashCode();  // should and do generate a warning here
37  	}
38  	int bar3(int x) {
39  		Object y = null;
40  		if (x > 0) y = "";
41  		return y.hashCode();  // should generate a warning here (but don't)
42  	}
43  	int bar4(int x) {
44  		Object y = null;
45  		if (x > 0) y = "";
46  		return y.hashCode();  // should generate a warning here (but don't)
47  	}
48  
49  }