Skip to content

fix: refactor AbstractTimeLineChartProblemStatistic constructor to not throw null pointer exception when unmarshalled by JaxB #1551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 28, 2025

Conversation

Magnusrk
Copy link
Contributor

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 Magnusrk temporarily deployed to documentation (preview) April 25, 2025 13:09 — with GitHub Actions Inactive
@triceo
Copy link
Contributor

triceo commented Apr 25, 2025

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.

Copy link
Contributor

@triceo triceo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done, @Magnusrk!
Will merge after the final review comment is resolved and the build is green.

@Magnusrk Magnusrk temporarily deployed to documentation (preview) April 28, 2025 10:22 — with GitHub Actions Inactive
@Magnusrk Magnusrk changed the title Refactored AbstractTimeLineChartProblemStatistic constructor to not throw null pointer exception when unmarshalled by JaxB fix:AbstractTimeLineChartProblemStatistic constructor to not throw null pointer exception when unmarshalled by JaxB Apr 28, 2025
@Magnusrk Magnusrk changed the title fix:AbstractTimeLineChartProblemStatistic constructor to not throw null pointer exception when unmarshalled by JaxB fix: AbstractTimeLineChartProblemStatistic constructor to not throw null pointer exception when unmarshalled by JaxB Apr 28, 2025
@Magnusrk Magnusrk changed the title fix: AbstractTimeLineChartProblemStatistic constructor to not throw null pointer exception when unmarshalled by JaxB fix: refactor AbstractTimeLineChartProblemStatistic constructor to not throw null pointer exception when unmarshalled by JaxB Apr 28, 2025
@Magnusrk Magnusrk temporarily deployed to documentation (preview) April 28, 2025 11:18 — with GitHub Actions Inactive
@triceo triceo temporarily deployed to documentation (preview) April 28, 2025 13:03 — with GitHub Actions Inactive
@triceo triceo merged commit 2456d9d into TimefoldAI:main Apr 28, 2025
33 of 34 checks passed
@triceo
Copy link
Contributor

triceo commented Apr 28, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants