aerie icon indicating copy to clipboard operation
aerie copied to clipboard

NumberFormatException when serializing infinite floating point resource

Open mattdailis opened this issue 2 years ago • 0 comments

Java floating point numbers may take on the values -Infinity, Infinity, and NaN. These three values are not serializable to the JSON number type, and result in variants of the following exception:

java.lang.NumberFormatException: Character I is neither a decimal digit number, decimal point, nor "e" notation exponential mark.
	at java.base/java.math.BigDecimal.<init>(Unknown Source)
	at java.base/java.math.BigDecimal.<init>(Unknown Source)
	at java.base/java.math.BigDecimal.<init>(Unknown Source)
	at java.base/java.math.BigDecimal.valueOf(Unknown Source)
	at gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue.of(SerializedValue.java:143)
	at gov.nasa.jpl.aerie.merlin.framework.Registrar$2$1.serialize(Registrar.java:88)
	at gov.nasa.jpl.aerie.merlin.framework.Registrar$2$1.serialize(Registrar.java:76)
	at gov.nasa.jpl.aerie.merlin.driver.engine.SimulationEngine.extractRealDynamics(SimulationEngine.java:657)
	at gov.nasa.jpl.aerie.merlin.driver.engine.SimulationEngine.serializeProfile(SimulationEngine.java:649)
	at gov.nasa.jpl.aerie.merlin.driver.engine.SimulationEngine.computeResults(SimulationEngine.java:469)
	at gov.nasa.jpl.aerie.merlin.driver.SimulationDriver.simulate(SimulationDriver.java:107)
	at gov.nasa.jpl.aerie.merlin.server.services.LocalMissionModelService.runSimulation(LocalMissionModelService.java:230)
	at gov.nasa.jpl.aerie.merlin.server.services.SynchronousSimulationAgent.simulate(SynchronousSimulationAgent.java:76)
	at gov.nasa.jpl.aerie.merlin.worker.MerlinWorkerAppDriver.main(MerlinWorkerAppDriver.java:81)

This exception occurs at the end of simulation when serializing values.

The user experience here is sub-optimal, since the feedback is given only at the end of simulation, and there is no indication of what a user should to do resolve this. The purpose of this ticket is to start a discussion and try to arrive at a better user experience, by one or more of the following:

  1. Providing a better error message
  2. Providing that error message sooner
  3. Supporting -Infinity, Infinity, and NaN in Aerie resources by encoding them as strings
  4. Providing guardrails in the merlin framework to protect against these errors

mattdailis avatar Aug 01 '23 17:08 mattdailis