IDEA-CR-20904 fixes after review (IDEA-123301 Show a warning if 'List<@Nullable X>' is passed to a place where 'List<@NotNull X'> is expected)

supported maps, inheritance, returns, functional expressions
This commit is contained in:
peter
2017-05-15 16:16:19 +02:00
parent d8f61ec1ac
commit 582f0f9571
9 changed files with 193 additions and 35 deletions
@@ -0,0 +1,8 @@
import typeUse.*;
import java.util.*;
class MyList<T extends @NotNull Number> extends ArrayList<T> {}
class SubList extends <warning descr="Nullable type arguments where non-null ones are expected">MyList</warning><@Nullable Integer> {
<warning descr="Nullable type arguments where non-null ones are expected">MyList</warning><@Nullable Integer> myList;
}
@@ -1,21 +1,46 @@
import typeUse.*;
import java.util.*;
import java.util.function.*;
class JC {
public static void main(String[] args) {
List<@Nullable String> list = new ArrayList<>();
print(<warning descr="Assigning a collection of nullable elements into a collection of non-null elements">list</warning>);
void testList() {
List<@Nullable String> nullableList = new ArrayList<>();
print(<warning descr="Assigning a collection of nullable elements into a collection of non-null elements">nullableList</warning>);
List<@NotNull String> <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">list2</warning> = list;
List<@NotNull String> <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">list2</warning> = nullableList;
List<@NotNull String> list3;
list2 <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">=</warning> list;
}
list2 <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">=</warning> nullableList;
List<? super @NotNull String> list4 = nullableList;
List<? extends @NotNull String> <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">list5</warning> = nullableList;
}
private static void print(List<@NotNull String> list) {
for (String s : list) {
System.out.println(s.length());
}
}
List<@Nullable String> getNullableList() {return new ArrayList<>();}
List<@NotNull String> testReturnValue() {
List<@Nullable String> list = new ArrayList<>();
Supplier<List<@NotNull String>> supplier = () -> <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">list</warning>;
Supplier<List<@NotNull String>> supplierRef = <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">this::getNullableList</warning>;
Supplier<List<@NotNull String>> supplier3 = () -> { return <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">list</warning>;};
return <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">list</warning>;
}
}
class Test<T extends @Nullable CharSequence> {
public void test() {
List<T> nullableList = new ArrayList<>();
List<? extends @NotNull CharSequence> <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">list2</warning> = nullableList;
}
}
@@ -0,0 +1,14 @@
import typeUse.*;
import java.util.*;
class JC {
void testMap() {
Map<@NotNull String, @NotNull String> <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">m1</warning> = new HashMap<@Nullable String, String>();
m1 <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">=</warning> new HashMap<String, @Nullable String>();
m1 = new HashMap<String, String>();
Map<@NotNull String, ? extends @NotNull String> <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">m2</warning> = new HashMap<@Nullable String, String>();
}
}