Skip to content

Fix XML parser DTD resolution and TMView resize race#34

Closed
Greengoblin007 wants to merge 1 commit intotoruzz:masterfrom
Greengoblin007:fix/xml-parser-and-view-race
Closed

Fix XML parser DTD resolution and TMView resize race#34
Greengoblin007 wants to merge 1 commit intotoruzz:masterfrom
Greengoblin007:fix/xml-parser-and-view-race

Conversation

@Greengoblin007
Copy link
Copy Markdown

Summary

Three small, independent fixes that surface together when opening files on macOS / Linux. With these in place, per-file resources (bookmarks, palettes) load correctly on those platforms again.

Bugs fixed

1. XMLParser cannot load any per-file resources XML on macOS/Linux

The resources XML carries <!DOCTYPE tmres SYSTEM \"resources\\tmres.dtd\">. With setValidating(true) the JDK parser tries to resolve that as a URI; the backslash and the relative path mean it fails on non-Windows with no protocol: resources\\tmres.dtd. The IOException propagates up to TMUI.openFile, the FileImage ends up without a TMFileResources, and the user's bookmarks/palettes silently disappear.

Fix: setValidating(false) plus a no-op EntityResolver that returns an empty input source for any external entity. Validation buys nothing here — the DTD isn't shipped in any build configuration I can find — and dropping it makes the parser portable.

2. TMFileResources.toXML keeps emitting the broken DTD reference

Even after the parser fix, every newly written XML still re-emitted the unresolvable DTD line, so any other XML consumer (or a future re-enabled validation) would hit the same failure. Removed it.

3. TMView componentResized listener can NPE on editorCanvas

The component listener is registered before editorCanvas is assigned in the constructor. Any layout pass that fires a resize event between those two points throws `NullPointerException: ... editorCanvas is null`. I have a reliable repro on macOS once any code triggers a revalidate() on the content pane while the frame is still being constructed. Cheap one-line guard.

4. TMUI.openFile leaves FileImage resource-less after a load failure

If parsing the resources XML throws, the catch block shows a dialog but never falls back to creating empty default resources. Closing the file then writes nothing, so anything the user added during the session (e.g. a fresh bookmark) is lost. Added the same default-resources fallback that the no-XML branch already uses.

Test plan

  • Build with mvn package (Java 17)
  • Open a file on macOS that previously triggered the parse error → no dialog, bookmarks/palettes load
  • Add bookmark, close → XML written without the DTD line, reopens cleanly
  • Open file repeatedly with various codecs/zooms → no NPE in the resize listener

🤖 Generated with Claude Code

Three small fixes that surface together when opening files
on macOS / Linux:

1. XMLParser: set validating=false and install a no-op
   EntityResolver. The resources XML references a relative
   DTD path with a backslash ("resources\\tmres.dtd") which
   the JDK parser tries to resolve as a URI; on non-Windows
   systems this throws "no protocol" IOException, the
   per-file resources fail to load, and bookmarks/palettes
   silently disappear.

2. TMFileResources.toXML: stop emitting the DTD declaration
   line — without validation it serves no purpose, and
   keeping it propagates the broken reference to every newly
   written XML.

3. TMView componentResized listener: guard against null
   editorCanvas. The listener is registered before
   editorCanvas is initialised in the constructor, so any
   layout pass that fires a resize between those points
   NPEs. Cheap defensive check.

4. TMUI.openFile: if loading the per-file resources XML
   throws, the FileImage was left without a TMFileResources,
   so closing the file produced no XML at all (and any
   newly-added bookmarks were lost). Fall back to default
   resources after a failed load.
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.

1 participant