mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
MR brings detection of nullable inconsistencies inside return expressions for generic types. Now it supports - Support of arbitrary generic type (previously only collections was supported) - Recursive detection of inconsistencies - Detection of assigning not-null to nullable (via option) GitOrigin-RevId: ed37ea02ca44db58698f36f2ca82c67171733e69
46 lines
2.1 KiB
Java
46 lines
2.1 KiB
Java
import typeUse.*;
|
|
import java.util.*;
|
|
import java.util.function.*;
|
|
|
|
class JC {
|
|
|
|
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> = nullableList;
|
|
|
|
List<@NotNull String> list3;
|
|
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="Returning a class with nullable type parameters when a class with non-null type parameters is expected">list</warning>;};
|
|
|
|
return <warning descr="Returning a class with nullable type parameters when a class with non-null type parameters is expected">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;
|
|
}
|
|
} |