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

This commit is contained in:
Andreas Dangel committed 2013-03-30 11:50:57 +01:00
1 parent 89e005fe49
commit be4c1adce6
3 files changed
+29 -4

No files matched your search

+1
View File
@@ -15,6 +15,7 @@ New Java rule:
????? ??, 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)
@@ -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){
@@ -427,4 +427,26 @@ class MultiCatch {
<source-type>java 1.7</source-type>
</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>