mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
OptionalAssignedToNull: added optional (sic!) warning on optional == null comparison
Fixes IDEA-187578 Inspection to detect when Optional is compared with null
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
// "Fix all 'Null value for Optional type' problems in file" "true"
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class Test {
|
||||
void test(Optional<String> opt) {
|
||||
if(!opt.isPresent()) {
|
||||
System.out.println("null!");
|
||||
}
|
||||
}
|
||||
|
||||
void test2 (Optional<String> opt) {
|
||||
/*comment*/
|
||||
if(opt.isPresent()) {
|
||||
System.out.println("null!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ public class Test {
|
||||
}
|
||||
|
||||
OptionalInt opt() {
|
||||
return OptionalInt.empty();
|
||||
return (/*comment*/OptionalInt.empty());
|
||||
}
|
||||
|
||||
void m(Optional<String> opt) {}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Fix all 'Null value for Optional type' problems in file" "true"
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class Test {
|
||||
void test(Optional<String> opt) {
|
||||
if(opt =<caret>= null) {
|
||||
System.out.println("null!");
|
||||
}
|
||||
}
|
||||
|
||||
void test2 (Optional<String> opt) {
|
||||
if(opt !=/*comment*/ null) {
|
||||
System.out.println("null!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ public class Test {
|
||||
}
|
||||
|
||||
OptionalInt opt() {
|
||||
return null;
|
||||
return (/*comment*/null);
|
||||
}
|
||||
|
||||
void m(Optional<String> opt) {}
|
||||
|
||||
Reference in New Issue
Block a user