Fix StackOverflowError due to non-commuting TransitionFunctionImpl.combineWith#281
Open
marcus-h wants to merge 1 commit intosecure-software-engineering:developfrom
Open
Fix StackOverflowError due to non-commuting TransitionFunctionImpl.combineWith#281marcus-h wants to merge 1 commit intosecure-software-engineering:developfrom
marcus-h wants to merge 1 commit intosecure-software-engineering:developfrom
Conversation
marcus-h
commented
Apr 23, 2026
…mbineWith According to the theory, the combineWith operation of the TransitionFunctionImpl class has to be, among other things, commuative. This can result in a StackOverflowError (see VectorTest.testNoStackOverflowDueToNonCommutativeCombineWith for a reproducer). Excerpt from the stack trace: ... at wpds.impl.PostStar.update(PostStar.java:335) at wpds.impl.PostStar$HandleNormalListener.onOutTransitionAdded(PostStar.java:227) at wpds.impl.WeightedPAutomaton.addWeightForTransition(WeightedPAutomaton.java:329) at sync.pds.solver.SyncPDSSolver$4.addWeightForTransition(SyncPDSSolver.java:194) at wpds.impl.PostStar.update(PostStar.java:335) at wpds.impl.PostStar$HandleNormalListener.onOutTransitionAdded(PostStar.java:227) at wpds.impl.WeightedPAutomaton.addWeightForTransition(WeightedPAutomaton.java:329) at sync.pds.solver.SyncPDSSolver$4.addWeightForTransition(SyncPDSSolver.java:194) at wpds.impl.PostStar.update(PostStar.java:335) at wpds.impl.PostStar$HandleNormalListener.onOutTransitionAdded(PostStar.java:227) at wpds.impl.WeightedPAutomaton.addWeightForTransition(WeightedPAutomaton.java:329) at sync.pds.solver.SyncPDSSolver$4.addWeightForTransition(SyncPDSSolver.java:194) at wpds.impl.PostStar.update(PostStar.java:335) at wpds.impl.PostStar$HandleNormalListener.onOutTransitionAdded(PostStar.java:227) at wpds.impl.WeightedPAutomaton.addWeightForTransition(WeightedPAutomaton.java:329) at sync.pds.solver.SyncPDSSolver$4.addWeightForTransition(SyncPDSSolver.java:194) at wpds.impl.PostStar.update(PostStar.java:335) ... When combining the two paths in doSth, a new TransitionFunctionImpl is created where the statement sequences are merged but the stateChangeStatement from one of the path is used. The latter causes the PostStar.update <-> WeightedPAutomaton.addWeightForTransition "ping-pong". In order to fix this, store stateChangeStatement(s) from both paths in a set. Implementation note: a LinkedHashSet is used so the getStateChangeStatement() can be easily implemented (whether the method itself is "meaningful" is debatable, though).
swissiety
requested changes
Apr 27, 2026
Comment on lines
+73
to
78
| public TransitionFunctionImpl( | ||
| @NonNull Multimap<Transition, StatementSequence> transitionStatementSequences, | ||
| @NonNull LinkedHashSet<Statement> stateChangeStatements) { | ||
| this.stateChangeSequences = ImmutableMultimap.copyOf(transitionStatementSequences); | ||
| this.stateChangeStatements = new LinkedHashSet<>(stateChangeStatements); | ||
| } |
Member
There was a problem hiding this comment.
as this is the only ctor using/storing multiple elements it seems to make sense to create a seperate specialized class for it and keep storing the single element here.
Author
There was a problem hiding this comment.
Hmm what's the benefit of a separate class? The single element case is handled in the ctor above. I could also make this ctor private (if you're worried about the class' API - it would make overriding the combineWith method a bit more cumbersome, though).
Member
There was a problem hiding this comment.
less memory / no linked list overhead - in the cases where we don't need it. I haven't benchmarked it but it seems like a core element that can be generated quite some times.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.