forked from phoedos/pmd
Fixed 1597987: ArrayIndexOutOfBounds in new DaaRule
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4810 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -16,7 +16,7 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
|||||||
*/
|
*/
|
||||||
public class DAAPathFinder {
|
public class DAAPathFinder {
|
||||||
private static final int MAX_PATHS = 5000;
|
private static final int MAX_PATHS = 5000;
|
||||||
private static final int MAX_PATH_LENGTH = 2000;
|
private static final int MAX_PATH_LENGTH = 1000;
|
||||||
|
|
||||||
private IDataFlowNode rootNode;
|
private IDataFlowNode rootNode;
|
||||||
private Executable shim;
|
private Executable shim;
|
||||||
@ -60,7 +60,8 @@ public class DAAPathFinder {
|
|||||||
* Builds up the path.
|
* Builds up the path.
|
||||||
* */
|
* */
|
||||||
private void phase2(boolean flag) {
|
private void phase2(boolean flag) {
|
||||||
while (!currentPath.isEndNode() && currentPath.getLength() < MAX_PATH_LENGTH) {
|
while (!currentPath.isEndNode()
|
||||||
|
&& currentPath.getLength() < MAX_PATH_LENGTH) { // lockup in special cases, see bug 1461873
|
||||||
if (currentPath.isBranch() || currentPath.isFirstDoStatement()) {
|
if (currentPath.isBranch() || currentPath.isFirstDoStatement()) {
|
||||||
if (flag) {
|
if (flag) {
|
||||||
addNodeToTree();
|
addNodeToTree();
|
||||||
@ -119,8 +120,11 @@ public class DAAPathFinder {
|
|||||||
if (currentPath.isBranch()) { // TODO WHY????
|
if (currentPath.isBranch()) { // TODO WHY????
|
||||||
PathElement last = (PathElement) stack.getLastLeaf().getUserObject();
|
PathElement last = (PathElement) stack.getLastLeaf().getUserObject();
|
||||||
IDataFlowNode inode = currentPath.getLast();
|
IDataFlowNode inode = currentPath.getLast();
|
||||||
IDataFlowNode child = (IDataFlowNode) inode.getChildren().get(last.currentChild);
|
if (inode.getChildren().size() > last.currentChild) {
|
||||||
this.currentPath.addLast(child);
|
// for some unknown reasons last.currentChild might not be a children of inode, see bug 1597987
|
||||||
|
IDataFlowNode child = (IDataFlowNode) inode.getChildren().get(last.currentChild);
|
||||||
|
this.currentPath.addLast(child);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
IDataFlowNode inode = currentPath.getLast();
|
IDataFlowNode inode = currentPath.getLast();
|
||||||
IDataFlowNode child = (IDataFlowNode) inode.getChildren().get(0); //TODO ???? IMPORTANT - ERROR?
|
IDataFlowNode child = (IDataFlowNode) inode.getChildren().get(0); //TODO ???? IMPORTANT - ERROR?
|
||||||
@ -199,6 +203,7 @@ public class DAAPathFinder {
|
|||||||
}
|
}
|
||||||
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) last.getParent();
|
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) last.getParent();
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
|
// for some unknown reasons parent might be null, see bug 1597987
|
||||||
parent.remove(last);
|
parent.remove(last);
|
||||||
}
|
}
|
||||||
last = stack.getLastLeaf();
|
last = stack.getLastLeaf();
|
||||||
@ -293,6 +298,7 @@ public class DAAPathFinder {
|
|||||||
DefaultMutableTreeNode treeNode = stack.getLastLeaf();
|
DefaultMutableTreeNode treeNode = stack.getLastLeaf();
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
if (treeNode.getParent() != null) {
|
if (treeNode.getParent() != null) {
|
||||||
|
// for some unknown reasons the parent of treeNode might be null, see bug 1597987
|
||||||
int childCount = treeNode.getParent().getChildCount();
|
int childCount = treeNode.getParent().getChildCount();
|
||||||
for (int i = 0; i < childCount; i++) {
|
for (int i = 0; i < childCount; i++) {
|
||||||
DefaultMutableTreeNode tNode = (DefaultMutableTreeNode) treeNode.getParent().getChildAt(i);
|
DefaultMutableTreeNode tNode = (DefaultMutableTreeNode) treeNode.getParent().getChildAt(i);
|
||||||
|
Reference in New Issue
Block a user