Fix NPE in StochMathMapping for symbol-less rate expressions#1672
Merged
Fix NPE in StochMathMapping for symbol-less rate expressions#1672
Conversation
…xpressions
`Expression.getSymbols()` is documented to return null when the expression
has no free symbols (see Expression.java:545). The general-kinetics path
in StochMathMapping was iterating over the result with an unguarded
for-each, producing an NPE whose corpus signature is:
Cannot read the array length because "<local7>" is null
at cbit.vcell.mapping.StochMathMapping.getProbabilityRate
(StochMathMapping.java:145)
This trips when a non-mass-action rate expression flattens to a constant
or otherwise contains no free symbols (e.g. a Michaelis-Menten rate where
all parameters and species have already been resolved upstream). The fix
mirrors the established null-guard pattern already used in
AbstractStochMathMapping.getSubstitutedExpr (line 155).
The general-kinetics fallback in StochasticTransformer is the intended
path for non-mass-action kinetics — it takes the authoritative reaction
rate as a net flux and uses max(rate, 0) as the irreversible forward
rate, which is exactly the right shape for stochastic simulation. The
NPE was preventing that path from completing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
danv61
approved these changes
Apr 30, 2026
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.
Summary
StochMathMapping.getProbabilityRate(... GeneralKineticsStochasticFunction ...).Expression.getSymbols()is documented to return null when the expression has no free symbols (seeExpression.java:545); the for-each at line 145 didn't guard for that, producing an NPE.Cannot read the array length because "<local7>" is null at StochMathMapping.getProbabilityRate(StochMathMapping.java:145).AbstractStochMathMapping.getSubstitutedExpr(line 155).Why now
Triage of a user-support-email log corpus identified this as the next-largest unaddressed cluster: 6 distinct user incidents, 25 stack traces, multiple distinct user models. Users currently see a deep NPE rather than a successful stochastic math generation.
Why this trips
The
GeneralKineticsStochasticTransformerfallback is the intended path for non-mass-action rate laws (Michaelis-Menten, Hill, etc.) — it takes the authoritative reaction rate as a net flux and usesmax(rate, 0)as the irreversible forward rate, which is exactly the right shape for stochastic simulation. The NPE was preventing that path from completing whenever the rate expression flattened to no free symbols (e.g. a constant rate, or a rate where all parameters and species have already been resolved upstream).Diff
Test plan
mvn compile -pl vcell-core -am— builds cleanmvn test -pl vcell-core -Dgroups="Fast"— same pass/fail count as master; only failure is the pre-existing unrelatedVCellDataTest.test_3DPoetry environmental error🤖 Generated with Claude Code