Encountered the following error after running NonDex:
in org.jfree.chart.plot.PolarPlotTest
[ERROR] org.jfree.chart.plot.PolarPlotTest.testGetLegendItems2 Time elapsed: 0.053 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <A> but was: <C>
at org.jfree.chart@2.0.0-SNAPSHOT/org.jfree.chart.plot.PolarPlotTest.testGetLegendItems2(PolarPlotTest.java:108)
REASON AND FIX
The tests fail when the function values of 'items' are compared using assert statements intestGetLegendItems2. This is because the 'renderers' in Plot are set using HashMap which maintains a non-deterministic order.
According to HashMap documentation,
"This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time."
This can be solved by changing from HashMap to LinkedHashMap to maintain a permanent deterministic order.
Reproduce:
The following command can be used to replicate the failures and validate the fix:
This PR aims to fix a test:
This was found by using the NonDex tool.
Encountered the following error after running NonDex:
REASON AND FIX
The tests fail when the function values of 'items' are compared using assert statements in
testGetLegendItems2
. This is because the 'renderers' in Plot are set using HashMap which maintains a non-deterministic order.https://github.com/jfree/jfreechart/blob/e2d6788d594c51941ddae337ae666fda5c52ad9f/src/test/java/org/jfree/chart/plot/PolarPlotTest.java#L103
https://github.com/jfree/jfreechart/blob/e2d6788d594c51941ddae337ae666fda5c52ad9f/src/main/java/org/jfree/chart/plot/PolarPlot.java#L261
According to HashMap documentation, "This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time."
This can be solved by changing from HashMap to
LinkedHashMap
to maintain a permanent deterministic order.Reproduce:
The following command can be used to replicate the failures and validate the fix:
Environment:
No user-facing change. No dependency upgrade.