mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplifiable assertion: don't assume types are compatible
EA-117420 - NPE: SimplifiableAssertionInspection$SimplifyAssertFix.replaceAssertLiteralWithAssertEquals
This commit is contained in:
+10
-10
@@ -256,18 +256,18 @@ public abstract class SimplifiableAssertionInspection extends BaseInspection {
|
||||
final PsiType lhsType = lhs.getType();
|
||||
final PsiType rhsType = rhs.getType();
|
||||
if (lhsType != null && rhsType != null && PsiUtil.isLanguageLevel5OrHigher(lhs)) {
|
||||
if (isPrimitiveAndBoxedWithOverloads(lhsType, rhsType)) {
|
||||
final PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(rhsType);
|
||||
assert unboxedType != null;
|
||||
buf.append(lhs.getText()).append(",(").append(unboxedType.getCanonicalText()).append(')').append(rhs.getText());
|
||||
}
|
||||
else if (isPrimitiveAndBoxedWithOverloads(rhsType, lhsType)) {
|
||||
final PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(lhsType);
|
||||
assert unboxedType != null;
|
||||
buf.append('(').append(unboxedType.getCanonicalText()).append(')').append(lhs.getText()).append(',').append(rhs.getText());
|
||||
final PsiPrimitiveType rhsUnboxedType = PsiPrimitiveType.getUnboxedType(rhsType);
|
||||
if (isPrimitiveAndBoxedWithOverloads(lhsType, rhsType) && rhsUnboxedType != null) {
|
||||
buf.append(lhs.getText()).append(",(").append(rhsUnboxedType.getCanonicalText()).append(')').append(rhs.getText());
|
||||
}
|
||||
else {
|
||||
buf.append(lhs.getText()).append(',').append(rhs.getText());
|
||||
final PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(lhsType);
|
||||
if (isPrimitiveAndBoxedWithOverloads(rhsType, lhsType) && unboxedType != null) {
|
||||
buf.append('(').append(unboxedType.getCanonicalText()).append(')').append(lhs.getText()).append(',').append(rhs.getText());
|
||||
}
|
||||
else {
|
||||
buf.append(lhs.getText()).append(',').append(rhs.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import org.junit.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class JUnit4TestCase {
|
||||
|
||||
@Test
|
||||
public void testOne() {
|
||||
assertEquals("1", 1);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import org.junit.*;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class JUnit4TestCase {
|
||||
|
||||
@Test
|
||||
public void testOne() {
|
||||
<caret>assertTrue("1".equals(1));
|
||||
}
|
||||
}
|
||||
+1
@@ -32,6 +32,7 @@ public class SimplifiableJUnitAssertionFixTest extends IGQuickFixesTestCase {
|
||||
public void testDoublePrimitive() { doTest(); }
|
||||
public void testEqualsToTrueJUnit5() { doTest(); }
|
||||
public void testTrueToEqualsJUnit5() { doTest(); }
|
||||
public void testTrueToEqualsBetweenIncompatibleTypes() { doTest(); }
|
||||
public void testFalseToNotEqualsJUnit4() { doTest(); }
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user