mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 05:09:37 +07:00
Adds external Contract for Objects::toString
Fixes IDEA-197174 Nullable inspection control flow with Objects.toString check enhancement
This commit is contained in:
@@ -95,4 +95,28 @@ class ContractReturnValues {
|
||||
|
||||
@Contract("null -> fail")
|
||||
native static void check(@Nullable String s);
|
||||
|
||||
// IDEA-197174
|
||||
private void withNullInspectionInsideIf(@Nullable String text) {
|
||||
if (!Objects.toString(text, "").isEmpty()) {
|
||||
System.out.println(text.trim());
|
||||
}
|
||||
}
|
||||
|
||||
private void withNullInspectionOutsideIf(@Nullable String text) {
|
||||
if (Objects.toString(text, "").isEmpty()) {
|
||||
System.out.println("Is Empty");
|
||||
} else {
|
||||
System.out.println(text.trim());
|
||||
}
|
||||
}
|
||||
|
||||
private void withNullInspectionWithoutDefaultValue(@Nullable String text) {
|
||||
if (Objects.toString(text).isEmpty()) {
|
||||
System.out.println("Is Empty");
|
||||
} else {
|
||||
// In this case system can produce NullPointerException, because Objects.toString(String str) calls methods String.valueOf()
|
||||
System.out.println(text.<warning descr="Method invocation 'trim' may produce 'java.lang.NullPointerException'">trim</warning>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1788,6 +1788,12 @@
|
||||
<item name='java.util.NavigableSet java.util.SortedSet<E> tailSet(E)'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='java.util.Objects java.lang.String toString(java.lang.Object, java.lang.String)'>
|
||||
<annotation name='org.jetbrains.annotations.Contract'>
|
||||
<val name="value" val=""null, _ -> param2""/>
|
||||
<val name="pure" val="true"/>
|
||||
</annotation>
|
||||
</item>
|
||||
<item name='java.util.Optional T get()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
<annotation name='org.jetbrains.annotations.Contract'>
|
||||
|
||||
Reference in New Issue
Block a user