mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
Optional compared with null: do not warn when subsequent isPresent check is found
IDEA-187578 Inspection to detect when Optional is compared with null
This commit is contained in:
+21
@@ -17,4 +17,25 @@ public class Test {
|
||||
}
|
||||
}
|
||||
|
||||
void test3 (Optional<String> opt) {
|
||||
// this case is ignored
|
||||
if(opt == null || !opt.isPresent()) {
|
||||
System.out.println("null or absent");
|
||||
}
|
||||
}
|
||||
|
||||
void test4 (Optional<String> opt) {
|
||||
// this case is ignored as well
|
||||
if(opt != null && opt.isPresent()) {
|
||||
System.out.println("present");
|
||||
}
|
||||
}
|
||||
|
||||
void test5 (Optional<String> opt, Optional<String> opt2) {
|
||||
// warn: different optionals used
|
||||
if(opt.isPresent() && opt2.isPresent()) {
|
||||
System.out.println("present");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -16,4 +16,25 @@ public class Test {
|
||||
}
|
||||
}
|
||||
|
||||
void test3 (Optional<String> opt) {
|
||||
// this case is ignored
|
||||
if(opt == null || !opt.isPresent()) {
|
||||
System.out.println("null or absent");
|
||||
}
|
||||
}
|
||||
|
||||
void test4 (Optional<String> opt) {
|
||||
// this case is ignored as well
|
||||
if(opt != null && opt.isPresent()) {
|
||||
System.out.println("present");
|
||||
}
|
||||
}
|
||||
|
||||
void test5 (Optional<String> opt, Optional<String> opt2) {
|
||||
// warn: different optionals used
|
||||
if(opt != null && opt2.isPresent()) {
|
||||
System.out.println("present");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user