mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-10 13:17:09 +07:00
ObviousNullCheckInspection: improve extraction of side-effect statements when ternary operator or short-circuiting logic is involved.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// "Fix all 'Null-check method is called with obviously non-null argument' problems in file" "true"
|
||||
import java.util.Objects;
|
||||
|
||||
public class Test {
|
||||
Test(int i) {
|
||||
}
|
||||
|
||||
public static void testTernaryLeft() {
|
||||
if (args.length > 0) {
|
||||
new Test(1);
|
||||
new Test(2);
|
||||
}
|
||||
}
|
||||
|
||||
public static void testTernaryRight() {
|
||||
if (args.length <= 0) {
|
||||
new Test(2);
|
||||
new Test(3);
|
||||
}
|
||||
}
|
||||
|
||||
public static void testTernaryBoth() {
|
||||
if (args.length > 0) {
|
||||
new Test(1);
|
||||
} else {
|
||||
new Test(2);
|
||||
new Test(3);
|
||||
}
|
||||
}
|
||||
|
||||
public static void testAndTernarySimply() {
|
||||
new Test(1).hashCode();
|
||||
}
|
||||
|
||||
public static void testAndTernaryBranch() {
|
||||
if (new Test(1).hashCode() <= 0 || args.length <= 0) {
|
||||
new Test(2);
|
||||
}
|
||||
}
|
||||
|
||||
public static void testAndBoth() {
|
||||
if (new Test(1).hashCode() > 0) {
|
||||
new Test(2).hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static void testAndTwoOfThree() {
|
||||
if (new Test(1).hashCode() > 0) {
|
||||
new Test(2).hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static void testAndTwoOfThreePlusBranch() {
|
||||
if (new Test(1).hashCode() > 0 && new Test(2).hashCode() > 0
|
||||
&& args.length > 0) {
|
||||
new Test(3).toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void testAndOrMixed() {
|
||||
if (new Test(1).hashCode() <= 0 || new Test(2).hashCode() <= 0) {
|
||||
if (new Test(3).hashCode() + new Test(4).hashCode() > 1) {
|
||||
new Test(5).hashCode();
|
||||
new Test(6).hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
// "Fix all 'Null-check method is called with obviously non-null argument' problems in file" "true"
|
||||
import java.util.Objects;
|
||||
|
||||
public class Test {
|
||||
Test(int i) {
|
||||
}
|
||||
|
||||
public static void testTernaryLeft() {
|
||||
Objects.requireNonNull("xyz" +<caret> (args.length > 0 ? new Test(1) + ":" + new Test(2) : ""));
|
||||
}
|
||||
|
||||
public static void testTernaryRight() {
|
||||
Objects.requireNonNull("xyz" + (args.length > 0 ? "null" : new Test(2)+":"+new Test(3)));
|
||||
}
|
||||
|
||||
public static void testTernaryBoth() {
|
||||
Objects.requireNonNull("xyz" + (args.length > 0 ? new Test(1) : new Test(2)+":"+new Test(3)));
|
||||
}
|
||||
|
||||
public static void testAndTernarySimply() {
|
||||
Objects.requireNonNull("xyz" + (new Test(1).hashCode() > 0 && args.length > 0 ? "x" : "y"));
|
||||
}
|
||||
|
||||
public static void testAndTernaryBranch() {
|
||||
Objects.requireNonNull("xyz" + (new Test(1).hashCode() > 0 && args.length > 0 ? "x" : new Test(2)));
|
||||
}
|
||||
|
||||
public static void testAndBoth() {
|
||||
Objects.requireNonNull("xyz" + (new Test(1).hashCode() > 0 && new Test(2).hashCode() > 0 ? "x" : "y"));
|
||||
}
|
||||
|
||||
public static void testAndTwoOfThree() {
|
||||
Objects.requireNonNull("xyz" + (new Test(1).hashCode() > 0 && new Test(2).hashCode() > 0
|
||||
&& args.length > 0 ? "x" : "y"));
|
||||
}
|
||||
|
||||
public static void testAndTwoOfThreePlusBranch() {
|
||||
Objects.requireNonNull("xyz" + (new Test(1).hashCode() > 0 && new Test(2).hashCode() > 0
|
||||
&& args.length > 0 ? new Test(3).toString() : "y"));
|
||||
}
|
||||
|
||||
public static void testAndOrMixed() {
|
||||
Objects.requireNonNull("xyz" + (new Test(1).hashCode() > 0 && new Test(2).hashCode() > 0
|
||||
|| new Test(3).hashCode() + new Test(4).hashCode() > 1 &&
|
||||
new Test(5).hashCode() + new Test(6).hashCode() > 2));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user