Skip to content

Commit 0da8350

Browse files
jcschaffclaude
andcommitted
Fix NPE in ParticleMathMapping when reaction has non-mass-action kinetics
`transformToStochastic` returns a `GeneralKineticsStochasticFunction` when a reaction's rate law cannot be reduced to mass-action form (e.g. Hill / Michaelis-Menten kinetics). The existing `instanceof MassActionStochasticFunction` check correctly leaves `maFunc` null in that case, but the next line dereferenced it unconditionally (`maFunc.forwardRate()`), producing an NPE far from the real cause. Particle math mapping requires mass-action shape regardless, so the correct behavior is to throw the same `MappingException` whether `maFunc` is null or has both rates null. Adding `maFunc == null ||` to the guard yields a descriptive error pointing at the offending reaction instead of an NPE. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c5f4f2c commit 0da8350

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

vcell-core/src/main/java/cbit/vcell/mapping/ParticleMathMapping.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,11 @@ else if(rp instanceof Product)
729729
{
730730
maFunc = (MassActionStochasticFunction)stochasticFunction;
731731
}
732-
if ((maFunc.forwardRate() == null && maFunc.reverseRate() == null))
732+
// transformToStochastic falls back to GeneralKineticsStochasticFunction
733+
// when the rate law can't be reduced to mass-action form (e.g. Hill /
734+
// Michaelis-Menten kinetics). Particle math mapping requires mass-action
735+
// shape, so report the same error in either case rather than NPE.
736+
if (maFunc == null || (maFunc.forwardRate() == null && maFunc.reverseRate() == null))
733737
{
734738
throw new MappingException("Cannot generate stochastic math mapping for the reaction:" + reactionStep.getName() + "\nLooking for the rate function according to the form of k1*Reactant1^Stoir1*Reactant2^Stoir2...-k2*Product1^Stoip1*Product2^Stoip2.");
735739
}

0 commit comments

Comments
 (0)