@ -136,7 +136,7 @@ public class UnnecessaryLocalBeforeReturnRule extends AbstractJavaRule {
|
||||
final ASTBlockStatement location = occ.getLocation().getFirstParentOfType(ASTBlockStatement.class);
|
||||
|
||||
// Is it used after initializing our "unnecessary" local but before the return statement?
|
||||
if (isAfter(location, initializerStmt) && isAfter(rtnStmt, location)) {
|
||||
if (location != null && isAfter(location, initializerStmt) && isAfter(rtnStmt, location)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -244,6 +244,23 @@ public class UnnecessaryLocalBeforeReturnFP {
|
||||
.make(i);
|
||||
return o; // true positive
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1804 [java] NPE with fields</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class ObjectCreator {
|
||||
|
||||
private static final String A = "";
|
||||
private static final String B = "" + A; // the existence of this line causes the NPE.
|
||||
|
||||
public Object create() {
|
||||
final Object o = new Object(A);
|
||||
return o;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user