IG: fix IOE when if has no condition (IDEA-176308)

This commit is contained in:
Bas Leijdekkers
2017-07-20 20:14:11 +02:00
parent ca606a6b04
commit e31945ac57
4 changed files with 13 additions and 3 deletions
@@ -78,7 +78,9 @@ public class IfCanBeAssertionInspection extends BaseInspection {
@Override
public void visitIfStatement(PsiIfStatement statement) {
super.visitIfStatement(statement);
if (statement.getElseBranch() == null && getThrownNewException(statement.getThenBranch()) != null) {
if (statement.getCondition() != null &&
statement.getElseBranch() == null &&
getThrownNewException(statement.getThenBranch()) != null) {
registerStatementError(statement);
}
}
@@ -1,6 +1,6 @@
<html>
<body>
This inspection reports <b>if</b> statements (with no <b>else</b> branch) throwing <code>java.lang.Throwable</code>.<br>
Reports <b>if</b> statements (with no <b>else</b> branch) throwing <code>java.lang.Throwable</code>.<br>
For example:<br>
<code><b>if</b> (param == 2) <b>throw new</b> Exception();</code>
@@ -0,0 +1,7 @@
class NoCondition {
void m(Object o) {
<caret>if () {
throw new NullPointerException("wtf?");
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,4 +35,5 @@ public class IfCanBeAssertionInspectionTest extends IGQuickFixesTestCase {
public void testRandomThrowable() { doTest(); }
public void testParentheses() { doTest(); }
public void testNoCondition() { assertQuickfixNotAvailable(); }
}