timefold-solver icon indicating copy to clipboard operation
timefold-solver copied to clipboard

Refactored AbstractTimeLineChartProblemStatistic constructor to not throw null pointer exception when unmarshalled by JaxB

Open Magnusrk opened this issue 7 months ago • 2 comments

When using the BenchmarkAggregatorFrame to unmarshall PlannerBenchmarkResult.xml with the problemStatisticType SCORE_CALCULATION_SPEED or MOVE_EVALUATION_SPEED the would result in null pointer exception due to empty JaxB noargs constructors calling the parameterized constructor with null as the PlannerBenchmarkResult.

Stacktrace

ai.timefold.solver.core.impl.io.jaxb.TimefoldXmlSerializationException: Failed to unmarshall a root element class (ai.timefold.solver.benchmark.impl.result.PlannerBenchmarkResult) from XML with overriding elements' namespaces: ([ElementNamespaceOverride{elementLocalName='solverConfig', namespaceOverride='https://timefold.ai/xsd/solver'}]).
	at ai.timefold.solver.core.impl.io.jaxb.GenericJaxbIO.readOverridingNamespace(GenericJaxbIO.java:208)
	at ai.timefold.solver.core.impl.io.jaxb.GenericJaxbIO.readOverridingNamespace(GenericJaxbIO.java:188)
	at ai.timefold.solver.benchmark.impl.result.BenchmarkResultIO.read(BenchmarkResultIO.java:94)
	at ai.timefold.solver.benchmark.impl.result.BenchmarkResultIO.readPlannerBenchmarkResult(BenchmarkResultIO.java:76)
	at ai.timefold.solver.benchmark.impl.result.BenchmarkResultIO.readPlannerBenchmarkResultList(BenchmarkResultIO.java:62)
	at ai.timefold.solver.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.initPlannerBenchmarkResultList(BenchmarkAggregatorFrame.java:241)
	at ai.timefold.solver.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.init(BenchmarkAggregatorFrame.java:140)
	at ai.timefold.solver.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.createAndDisplay(BenchmarkAggregatorFrame.java:109)
	at ai.timefold.solver.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.createAndDisplayFromXmlResource(BenchmarkAggregatorFrame.java:74)
	at BenchmarkApp.main(BenchmarkApp.java:19)
Caused by: jakarta.xml.bind.UnmarshalException: Unable to create an instance of ai.timefold.solver.benchmark.impl.statistic.scorecalculationspeed.ScoreCalculationSpeedProblemStatistic
Caused by: jakarta.xml.bind.UnmarshalException: Unable to create an instance of ai.timefold.solver.benchmark.impl.statistic.scorecalculationspeed.ScoreCalculationSpeedProblemStatistic

Magnusrk avatar Apr 25 '25 11:04 Magnusrk

Hello @Magnusrk! Thank you for your contribution.

As I'm sure you've noticed, the benchmarker (and specifically the aggregator) is the biggest accumulation of technical debt in our entire codebase. It has almost no test coverage, and that inevitably leads to regressions. (Which is not helped by the fact that the aggregator is only rarely used.)

Your PR presents an opportunity to introduce some test coverage. Would you mind adding a test for serialization and deserialization of the benchmark result? The way I imagine it working is:

  • Create manually a benchmark result XML.
  • Write a test which deserializes it, checks crucial values for correctness.
  • Write a test which serializes it back, check that the XML is correct. (Full string comparison ought to be enough here.)

Is this something you'd be willing to do? If so, please use AssertJ for assertions, as that will save you quite a lot of time and will be consistent with the rest of the solver codebase.

triceo avatar Apr 25 '25 13:04 triceo

Merged. Thank you again for your contribution, @Magnusrk!

triceo avatar Apr 28 '25 13:04 triceo