#1393 PMD hanging during DataflowAnomalyAnalysis

This commit is contained in:
Andreas Dangel 2015-09-18 10:17:01 +02:00
parent e1a41bdf98
commit 0f48fd501d
4 changed files with 51 additions and 5 deletions

View File

@ -17,6 +17,9 @@ public class Linker {
private final static Logger LOGGER = Logger.getLogger(Linker.class.getName());
private final static String CLASS_NAME = Linker.class.getCanonicalName();
/** Maximum loops to prevent hanging of PMD. See https://sourceforge.net/p/pmd/bugs/1393/ */
private static final int MAX_LOOPS = 100;
private final DataFlowHandler dataFlowHandler;
private List<StackObject> braceStack;
private List<StackObject> continueBreakReturnStack;
@ -37,7 +40,9 @@ public class Linker {
// the last index of the sequence.
LOGGER.fine("SequenceChecking continueBreakReturnStack elements");
SequenceChecker sc = new SequenceChecker(braceStack);
while (!sc.run()) {
int i = 0;
while (!sc.run() && i < MAX_LOOPS) {
i++;
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("After sc.run - starting Sequence checking loop with firstIndex=" + sc.getFirstIndex()
+ ", lastIndex " + sc.getLastIndex() + " with this StackList " + dump("braceStack", braceStack));

View File

@ -17,6 +17,9 @@ import net.sourceforge.pmd.lang.dfa.NodeType;
public class DAAPathFinder {
private static final int MAX_PATHS = 5000;
/** Maximum loops to prevent hanging of PMD. See https://sourceforge.net/p/pmd/bugs/1393/ */
private static final int MAX_LOOPS = 100;
private DataFlowNode rootNode;
private Executable shim;
private CurrentPath currentPath = new CurrentPath();
@ -59,7 +62,9 @@ public class DAAPathFinder {
* Builds up the path.
* */
private void phase2(boolean flag) {
while (!currentPath.isEndNode()) {
int i = 0;
while (!currentPath.isEndNode() && i < MAX_LOOPS) {
i++;
if (currentPath.isBranch() || currentPath.isFirstDoStatement()) {
if (flag) {
addNodeToTree();
@ -126,8 +131,9 @@ public class DAAPathFinder {
PathElement last = (PathElement) stack.getLastLeaf().getUserObject();
DataFlowNode inode = currentPath.getLast();
if (inode.getChildren().size() > last.currentChild) {
// for some unknown reasons last.currentChild might not be a children of inode, see bug 1597987
DataFlowNode child = inode.getChildren().get(last.currentChild);
// for some unknown reasons last.currentChild might not be a children of inode, see bug 1597987
// see https://sourceforge.net/p/pmd/bugs/606/
DataFlowNode child = inode.getChildren().get(last.currentChild);
this.currentPath.addLast(child);
}
} else {
@ -313,6 +319,7 @@ public class DAAPathFinder {
int counter = 0;
if (treeNode.getParent() != null) {
// for some unknown reasons the parent of treeNode might be null, see bug 1597987
// see https://sourceforge.net/p/pmd/bugs/606/
int childCount = treeNode.getParent().getChildCount();
for (int i = 0; i < childCount; i++) {
DefaultMutableTreeNode tNode = (DefaultMutableTreeNode) treeNode.getParent().getChildAt(i);

View File

@ -73,5 +73,38 @@ public class Foo {
}
}
]]></code>
</test-code>
</test-code>
<test-code>
<description>#1393 PMD hanging during DataflowAnomalyAnalysis</description>
<!-- Note: due to https://sourceforge.net/p/pmd/bugs/1383/ the 6 problems are false positives! -->
<expected-problems>6</expected-problems>
<code><![CDATA[
public class LoopTest {
public static void main(String[] args) {
int[] a = {1,2,3};
int[] b = {4,5,6};
int[] c = {7,8,9};
for (int i : a) {
if (i == 0) {
break;
} else {
boolean fail = false;
for (int j : b) {
boolean match = false;
for (int k : c) {
if (k == 42) {
match = true;
}
}
if (!match) {
fail = true;
}
}
}
}
}
}
]]></code>
</test-code>
</test-data>

View File

@ -18,6 +18,7 @@
* [#1384](https://sourceforge.net/p/pmd/bugs/1384/): NullPointerException in ConsecutiveLiteralAppendsRule
* [#1388](https://sourceforge.net/p/pmd/bugs/1388/): ConstructorCallsOverridableMethodRule doesn't work with params?
* [#1392](https://sourceforge.net/p/pmd/bugs/1392/): SimplifyStartsWith false-negative
* [#1393](https://sourceforge.net/p/pmd/bugs/1393/): PMD hanging during DataflowAnomalyAnalysis
* [#1394](https://sourceforge.net/p/pmd/bugs/1394/): dogfood.xml - Unable to exclude rules [UncommentedEmptyMethod]
* [#1395](https://sourceforge.net/p/pmd/bugs/1395/): UnusedPrivateMethod false positive for array element method call
* [#1396](https://sourceforge.net/p/pmd/bugs/1396/): PrematureDeclaration lambda false positive