Skip to content

Commit 2dc800b

Browse files
committed
Transitive relation exceeded should not fail the analysis
1 parent 830d17c commit 2dc800b

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

java-squid/src/main/java/org/sonar/java/se/SymbolicExecutionVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
2525
import org.sonar.java.ast.visitors.SubscriptionVisitor;
26+
import org.sonar.java.se.symbolicvalues.BinaryRelation;
2627
import org.sonar.plugins.java.api.tree.Tree;
2728

2829
import java.util.List;
@@ -39,7 +40,7 @@ public List<Tree.Kind> nodesToVisit() {
3940
public void visitNode(Tree tree) {
4041
try {
4142
tree.accept(new ExplodedGraphWalker(context));
42-
} catch (ExplodedGraphWalker.MaximumStepsReachedException | ExplodedGraphWalker.ExplodedGraphTooBigException exception) {
43+
} catch (ExplodedGraphWalker.MaximumStepsReachedException | ExplodedGraphWalker.ExplodedGraphTooBigException | BinaryRelation.TransitiveRelationExceededException exception) {
4344
LOG.debug("Could not complete symbolic execution: ", exception);
4445
}
4546

java-squid/src/main/java/org/sonar/java/se/symbolicvalues/BinaryRelation.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535

3636
public abstract class BinaryRelation {
3737

38-
static final String TRANSITIVE_RELATIONS_EXCEEDED = "Number of transitive relations exceeded!";
38+
public class TransitiveRelationExceededException extends RuntimeException {
39+
public TransitiveRelationExceededException() {
40+
super("Number of transitive relations exceeded!");
41+
}
42+
}
3943

4044
protected final Kind kind;
4145
protected final SymbolicValue leftOp;
@@ -93,7 +97,7 @@ protected RelationState resolveState(Collection<BinaryRelation> knownRelations,
9397
return RelationState.UNDETERMINED;
9498
}
9599
if (usedRelations.size() > 200) {
96-
throw new IllegalStateException(TRANSITIVE_RELATIONS_EXCEEDED);
100+
throw new TransitiveRelationExceededException();
97101
}
98102
for (BinaryRelation relation : knownRelations) {
99103
RelationState result = relation.implies(this);
@@ -210,7 +214,7 @@ protected BinaryRelation conjunction(BinaryRelation relation) {
210214
protected abstract BinaryRelation symmetric();
211215

212216
/**
213-
* @param a relation between symbolic values
217+
* @param relation a relation between symbolic values
214218
* @return a RelationState<ul>
215219
* <li>FULFILLED if the receiver implies that the supplied relation is true</li>
216220
* <li>UNFULFILLED if the receiver implies that the supplied relation is false</li>

java-squid/src/test/java/org/sonar/java/se/symbolicvalues/BinaryRelationsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ public void checkTransitiveLimit() {
512512
try {
513513
relation(EQUAL, first, last).resolveState(relations);
514514
fail("Transitive limit was exceeded, but not detected!");
515-
} catch (IllegalStateException e) {
516-
assertThat(e.getMessage()).isEqualTo(BinaryRelation.TRANSITIVE_RELATIONS_EXCEEDED);
515+
} catch (BinaryRelation.TransitiveRelationExceededException e) {
516+
assertThat(e.getMessage()).contains("exceeded");
517517
}
518518
}
519519

0 commit comments

Comments
 (0)