Skip to content

Commit f01cad4

Browse files
experiments with IntelliJ 2017.1.3
1 parent a872df0 commit f01cad4

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,7 @@ External annotations support | :white_check_mark: using .eea files | :white_che
224224
External annotations provided for common libraries | :red_circle: community effort with [lastnpe.org](http://lastnpe.org)| :white_check_mark: JDK, Guava | :white_check_mark: JDK
225225
IDE support to create external annotations | :white_check_mark: | :warning: using command line tools | :white_check_mark:
226226
Treat all types as @Nonnull by default, unless annotated wih @Nullable:white_check_mark: using @NonNullByDefault for each package, allows to define the scope: field, parameters, return, generic types, etc... | :white_check_mark: by default, customizable with @DefaultQualifier:white_check_mark: IDE setting :question: global?
227-
@Polynull support | :red_circle::white_check_mark: using [@PolyNull](https://checkerframework.org/manual/#qualifier-polymorphism) | :white_check_mark: using [@Contract](https://www.jetbrains.com/help/idea/2017.1/contract-annotations.html), for instance @Contract("!null->!null;null->null")
227+
@Polynull support | :red_circle::white_check_mark: using [@PolyNull](https://checkerframework.org/manual/#qualifier-polymorphism) | :white_check_mark: using [@Contract](https://www.jetbrains.com/help/idea/2017.1/contract-annotations.html), for instance @Contract("!null->!null;null->null")
228+
Method contract support (e.g. handle ``if(StringUtils.hasText(str)) {str...}`` | :red_circle: | :question: | :white_check_mark: using @Contract
229+
Automatic inference of nullability constraints in external libraries | :red_circle: | :red_circle: | :white_check_mark: for @NonNull and some @Contract. [Disabled for @Nullable due to too many false positives](https://youtrack.jetbrains.com/issue/IDEA-130063)
230+
Treat main, test or generated sources differently | :warning: not in IDE, unless ignoring all non-fatal errors for a source folder| :white_check_mark: | :white_check_mark:

ide-settings/eclipse-with-npe-analysis/org.eclipse.jdt.core.prefs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
6060
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
6161
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
6262
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
63-
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
63+
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=error
6464
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
6565
org.eclipse.jdt.core.compiler.problem.potentialNullReference=error
6666
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package packageNotAnnotated;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.eclipse.jdt.annotation.NonNull;
7+
import org.eclipse.jdt.annotation.Nullable;
8+
9+
/**
10+
* Created by slaurent on 16.05.17.
11+
*/
12+
public class IntelliJNullabilityTest {
13+
14+
public static void test() {
15+
MyClass<String> my = new MyClass<>();
16+
17+
my.echo(null);
18+
19+
MyNonNullGenericClass<@NonNull String> toto = new MyNonNullGenericClass<>();
20+
System.out.println(toto);
21+
22+
// IntelliJ bug : should complain
23+
MyNonNullGenericClass<@Nullable String> titi = new MyNonNullGenericClass<>();
24+
System.out.println(titi);
25+
26+
MyNullableGenericClass<String> t1 = new MyNullableGenericClass<>();
27+
MyNullableGenericClass<@NonNull String> t2 = new MyNullableGenericClass<>();
28+
MyNullableGenericClass<@Nullable String> t3 = new MyNullableGenericClass<>();
29+
30+
}
31+
32+
public static <T extends @Nullable CharSequence> void typeArgumentNonNullExplicit(T t) {
33+
System.out.println(t.hashCode());
34+
MyClass<T> my = new MyClass<>();
35+
36+
my.echo(null);
37+
38+
}
39+
40+
static class MyClass<E> {
41+
private List<E> objs = new ArrayList<>();
42+
43+
public void echo(E e) {
44+
objs.add(e);
45+
46+
@NonNull
47+
List<@NonNull String> list = new ArrayList<>();
48+
list.add(null); // null warning here
49+
}
50+
51+
}
52+
53+
static class MyNonNullGenericClass<@NonNull T extends @NonNull Object> {
54+
55+
}
56+
57+
static class MyNullableGenericClass<@Nullable T extends @Nullable Object> {
58+
59+
}
60+
}

0 commit comments

Comments
 (0)