Issue #594: fix demo chart scan when the project path contains a space#1013
Merged
Merged
Conversation
The demo's classpath scan resolved the chart package directory from URL.getFile(), which is percent-encoded. Any project path containing a space pointed at a non-existent directory, so no charts were found, the tree was built empty, and clicking its root node - a String user object that is now a leaf - threw a ClassCastException on the EDT. - resolve the package directory through URI instead of getFile(), for both the file and jar cases, and close the JarFile - fail loudly when the package is missing or no charts are found rather than handing back an empty/null list - check the node type in the tree listener instead of assuming every leaf carries a ChartInfo Also repairs DemoChartsTest, which stopped compiling when the ToolTips constructor changed; it went unnoticed because this module skips tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #594.
The bug
The reporter's classpath was
E:\FEE\2nd Term\XChart\...— note the space in2nd Term. That space is the whole story:DemoChartsUtilresolved the chart package directory withnew File(url.getFile()).URL.getFile()returns a percent-encoded path, so the space came back as%20and theFilepointed at a directory that does not exist.getClassesByFilereturned an empty list on!dir.exists()— silently. No charts discovered.XChartDemo.createNodestherefore built a tree with no children, leaving the root node"XChart Example Charts"(aStringuser object) as a leaf.valueChanged, which casts any leaf's user object toChartInfo→ClassCastException: String cannot be cast to ChartInfo.Verified directly:
This also explains the issue title — the tree looks empty, so users see no "file explorer".
Changes
URI, notgetFile()— for both thefileandjarbranches. The jar path is itself a URL, so it goes throughnew File(new URL(...).toURI())rather than being chopped at the first/, which keeps spaces and Windows drive letters intact. TheJarFileis now closed via try-with-resources (dropping the@SuppressWarnings("resource")).getAllDemoCharts()used to returnnullwhen the package was missing (an NPE waiting to happen increateNodes) and an empty list when nothing was found. Both now throwIllegalStateExceptionwith the offending URL, so this is diagnosable instead of mysterious.valueChangednow checksnodeInfo instanceof ChartInfo. Category and root nodes carry aString, and either can be a leaf; that should not kill the EDT.dir.listFiles().Test
DemoChartsUtilTestcopies the compiled demo classes into a temp directory whose name contains a space, points a parent-lessURLClassLoaderat it, and asserts the scan still finds charts. Confirmed red before the fix and green after:Two things worth flagging
DemoChartsTesthad stopped compiling — it callsnew ToolTips(chart), but that constructor now takes(Chart, boolean, ToolTipType). Repaired here as a one-liner, since it blocked running any test in this module.xchart-demosets<maven.test.skip>true</maven.test.skip>in its pom and CI never overrides it, so none of this module's tests — including the new one — run in CI. I left that alone as out of scope for this issue, but it's worth deciding on separately: the comment says it exists to skip test compilation duringrelease:prepare, which a release-profile-scoped setting could handle without disabling the tests everywhere.Verified locally with
mvn -pl xchart-demo test -Dmaven.test.skip=false: 81 tests, all passing.🤖 Generated with Claude Code