mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Report error in the case of accidental endless loop while searching for unused variables. Also, allow cancelling this search. (IDEA-164371)
This commit is contained in:
@@ -169,7 +169,14 @@ public class DefUseUtil {
|
||||
}
|
||||
}
|
||||
|
||||
Map<InstructionKey, InstructionState> stateMap = getStates(instructions);
|
||||
Map<InstructionKey, InstructionState> stateMap;
|
||||
try {
|
||||
stateMap = getStates(instructions);
|
||||
}
|
||||
catch (InstructionKey.OverflowException e) {
|
||||
LOG.error("Failed to compute paths in the control flow graph", e, flow.toString());
|
||||
return null;
|
||||
}
|
||||
InstructionState[] states = stateMap.values().toArray(new InstructionState[0]);
|
||||
Arrays.sort(states);
|
||||
|
||||
@@ -511,6 +518,7 @@ public class DefUseUtil {
|
||||
|
||||
Set<InstructionKey> visited = new THashSet<InstructionKey>(instructions.size());
|
||||
while (!myWalkThroughStack.isEmpty()) {
|
||||
ProgressManager.checkCanceled();
|
||||
InstructionKey fromKey = myWalkThroughStack.peekFrom();
|
||||
InstructionKey nextKey = myWalkThroughStack.popNext();
|
||||
addBackwardTrace(fromKey, nextKey);
|
||||
|
||||
@@ -42,6 +42,9 @@ class InstructionKey implements Comparable<InstructionKey> {
|
||||
}
|
||||
|
||||
InstructionKey push(int nextOffset, int returnOffset) {
|
||||
if(myCallStack.length > 100) { // normally it's way below 100, as it's the number of levels of nested 'finally' blocks
|
||||
throw new OverflowException(myOffset); // most likely the graph traversal is in an endless loop
|
||||
}
|
||||
int[] nextStack = ArrayUtil.append(myCallStack, returnOffset);
|
||||
return new InstructionKey(nextOffset, nextStack);
|
||||
}
|
||||
@@ -105,4 +108,10 @@ class InstructionKey implements Comparable<InstructionKey> {
|
||||
c = myCallStack.length - key.myCallStack.length;
|
||||
return c;
|
||||
}
|
||||
|
||||
static class OverflowException extends RuntimeException {
|
||||
public OverflowException(int offset) {
|
||||
super("Instruction key overflow at offset " + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user