pmd: fix #943 PreserveStackTrace false positive if a StringBuffer exists

This commit is contained in:
Andreas Dangel 2013-03-30 10:20:43 +01:00
parent b998e64819
commit c8c6aa16dd
3 changed files with 29 additions and 4 deletions

View File

@ -1,5 +1,6 @@
????? ??, 2013 - 5.0.3:
Fixed bug 943: PreserveStackTrace false positive if a StringBuffer exists
Fixed bug 945: PMD generates RuleSets it cannot read.
Fixed bug 958: Intermittent NullPointerException while loading XPath node attributes
Fixed bug 968: Issues with JUnit4 @Test annotation with expected exception (Thanks to Yiannis Paschalidis)

View File

@ -74,10 +74,12 @@ public class PreserveStackTraceRule extends AbstractJavaRule {
if ((child instanceof ASTName) && !target.equals(child.getImage()) && !child.hasImageEqualTo(target + FILL_IN_STACKTRACE)) {
Map<VariableNameDeclaration, List<NameOccurrence>> vars = ((ASTName) child).getScope().getVariableDeclarations();
for (VariableNameDeclaration decl: vars.keySet()) {
args = decl.getNode().jjtGetParent()
.getFirstDescendantOfType(ASTArgumentList.class);
if (args != null) {
ck(data, target, throwStatement, args);
if (decl.getImage().equals(child.getImage())) {
args = decl.getNode().jjtGetParent()
.getFirstDescendantOfType(ASTArgumentList.class);
if (args != null) {
ck(data, target, throwStatement, args);
}
}
}
} else if (child instanceof ASTClassOrInterfaceType){

View File

@ -425,4 +425,26 @@ class MultiCatch {
]]></code>
</test-code>
<test-code>
<description>#943 PreserveStackTrace false positive if a StringBuffer exists</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Stuff {
@SuppressWarnings("unused")
public void doStuff() throws SomeException {
try {
doMoreStuff();
} catch (Exception e) {
StringBuffer irrelevantSB = new StringBuffer("Irrelevant").append(" string").append(" buffer");
SomeException someException = new SomeException(e);
throw someException;
}
}
private void doMoreStuff() {
// Stuff happens
}
}
]]></code>
</test-code>
</test-data>