mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: fix IOE when if has no condition (IDEA-176308)
This commit is contained in:
+3
-1
@@ -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>
|
||||
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class NoCondition {
|
||||
void m(Object o) {
|
||||
<caret>if () {
|
||||
throw new NullPointerException("wtf?");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -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(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user