[java-annotations] getOrDefault 2nd parameter is marked as nullable

Fixes IDEA-367387 Mismatch between IDEA and JSpecify on HashMap.getDefault(...) nullness

GitOrigin-RevId: 6e90dcdac5b61aa91431f96d007261ad448ea522
This commit is contained in:
Tagir Valeev
2025-02-13 11:05:42 +00:00
committed by intellij-monorepo-bot
parent 90e67979e7
commit b007ebf865
3 changed files with 22 additions and 0 deletions
@@ -0,0 +1,13 @@
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.HashMap;
@NullMarked
class Main {
HashMap<String, String> map = new HashMap<>();
public @Nullable String example() {
return map.getOrDefault("key", null);
}
}
@@ -160,4 +160,10 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase {
setupTypeUseAnnotations("org.jspecify.annotations", myFixture);
doTest();
}
public void testJSpecifyGetOrDefault() {
addJSpecifyNullMarked(myFixture);
setupTypeUseAnnotations("org.jspecify.annotations", myFixture);
doTest();
}
}
@@ -3216,6 +3216,9 @@
<val name="pure" val="true"/>
</annotation>
</item>
<item name='java.util.HashMap V getOrDefault(java.lang.Object, V) 1'>
<annotation name='org.jetbrains.annotations.Nullable'/>
</item>
<item name='java.util.HashSet HashSet()'>
<annotation name='org.jetbrains.annotations.Contract'>
<val name="pure" val="true"/>