mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
[java-inspections] IDEA-379303 Nullable incompatibilities in constructor calls
GitOrigin-RevId: 927bd8ab332fe6f7c6c122d7670592c7ca141b5a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e0fe1c88cf
commit
31b5a6a950
+29
@@ -0,0 +1,29 @@
|
||||
package org.example;
|
||||
|
||||
import org.jspecify.annotations.NotNull;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
class ConstructorTest {
|
||||
interface NullableExpectedLib<K extends @Nullable Object> {
|
||||
}
|
||||
|
||||
static class NullableLibExpectedInArguments {
|
||||
NullableLibExpectedInArguments(NullableExpectedLib<@Nullable Object> l) {
|
||||
}
|
||||
}
|
||||
|
||||
void test(NullableExpectedLib<Object> l) {
|
||||
new NullableLibExpectedInArguments(<warning descr="Assigning a class with not-null type arguments when a class with nullable type arguments is expected">l</warning>);
|
||||
}
|
||||
|
||||
static class NullableLibExpectedInArguments2<T extends @Nullable Object> {
|
||||
NullableLibExpectedInArguments2(NullableExpectedLib<T> l) {
|
||||
}
|
||||
}
|
||||
|
||||
void test2(NullableExpectedLib<Object> l) {
|
||||
new NullableLibExpectedInArguments2<>(l);
|
||||
}
|
||||
}
|
||||
+9
-4
@@ -140,7 +140,6 @@ public class JSpecifyFilteredAnnotationTest extends LightJavaCodeInsightFixtureT
|
||||
new Pair<>("OutOfBoundsTypeVariable.java", 21), // see: IDEA-377707 (also see the commented case in warning matchers)
|
||||
new Pair<>("TypeParameterBounds.java", 40), // see: IDEA-377707
|
||||
|
||||
new Pair<>("AugmentedInferenceAgreesWithBaseInference.java", 33), // see: IDEA-377683
|
||||
new Pair<>("NullnessUnspecifiedTypeParameter.java", 33), // see: IDEA-377683
|
||||
new Pair<>("TypeVariableMinusNullVsTypeVariable.java", 28), // see: IDEA-377683
|
||||
new Pair<>("TypeVariableMinusNullVsTypeVariable.java", 30), // see: IDEA-377683
|
||||
@@ -206,9 +205,7 @@ public class JSpecifyFilteredAnnotationTest extends LightJavaCodeInsightFixtureT
|
||||
Set.of(
|
||||
new Pair<>("NotNullMarkedUseOfWildcardAsTypeArgument.java", 30), //IDEA-380248
|
||||
new Pair<>("SameTypeTypeVariable.java", 31), //IDEA-380143
|
||||
new Pair<>("SameTypeTypeVariable.java", 51), //IDEA-380143
|
||||
new Pair<>("SuperVsObject.java", 24), // see: IDEA-379303
|
||||
new Pair<>("SuperNullableForNonNullableTypeParameter.java", 27) // see: IDEA-379303
|
||||
new Pair<>("SameTypeTypeVariable.java", 51) //IDEA-380143
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -415,10 +412,12 @@ public class JSpecifyFilteredAnnotationTest extends LightJavaCodeInsightFixtureT
|
||||
private static class SkipIndividuallyFilter implements ErrorFilter {
|
||||
private final Set<Pair<String, Integer>> places;
|
||||
private final Set<Pair<String, Integer>> unusedPlaces;
|
||||
private final Map<Pair<String, Integer>, Integer> bothUsedPlaces;
|
||||
|
||||
private SkipIndividuallyFilter(Set<Pair<String, Integer>> places) {
|
||||
this.places = places;
|
||||
this.unusedPlaces = new HashSet<>(places);
|
||||
this.bothUsedPlaces = StreamEx.of(places).toMap(t -> t, t -> 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -443,6 +442,7 @@ public class JSpecifyFilteredAnnotationTest extends LightJavaCodeInsightFixtureT
|
||||
private boolean filter(Pair<@NotNull @NlsSafe String, Integer> pair) {
|
||||
if (places.contains(pair)) {
|
||||
unusedPlaces.remove(pair);
|
||||
bothUsedPlaces.merge(pair, -1, Integer::sum);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -450,6 +450,11 @@ public class JSpecifyFilteredAnnotationTest extends LightJavaCodeInsightFixtureT
|
||||
|
||||
@Override
|
||||
public void reportUnused() {
|
||||
for (Map.Entry<Pair<String, Integer>, Integer> entry : bothUsedPlaces.entrySet()) {
|
||||
if(entry.getValue() == 0) {
|
||||
unusedPlaces.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
if (unusedPlaces.isEmpty()) return;
|
||||
System.out.println("Some filters were unused; probably they are not actual anymore and should be excluded:\n"
|
||||
+ StringUtil.join(unusedPlaces, "\n"));
|
||||
|
||||
+7
@@ -540,6 +540,13 @@ public class NullableStuffInspectionTest extends LightJavaCodeInsightFixtureTest
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testConstructorCallIncompatibilitiesWithGeneric() {
|
||||
myInspection.REPORT_NOT_NULL_TO_NULLABLE_CONFLICTS_IN_ASSIGNMENTS = true;
|
||||
addJSpecifyNullMarked(myFixture);
|
||||
setupTypeUseAnnotations("org.jspecify.annotations", myFixture);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCallIncompatibilitiesWithGenericWithNotNullToNull() {
|
||||
myInspection.REPORT_NOT_NULL_TO_NULLABLE_CONFLICTS_IN_ASSIGNMENTS = false;
|
||||
addJSpecifyNullMarked(myFixture);
|
||||
|
||||
Reference in New Issue
Block a user