Fix XML parser DTD resolution and TMView resize race#34
Closed
Greengoblin007 wants to merge 1 commit intotoruzz:masterfrom
Closed
Fix XML parser DTD resolution and TMView resize race#34Greengoblin007 wants to merge 1 commit intotoruzz:masterfrom
Greengoblin007 wants to merge 1 commit intotoruzz:masterfrom
Conversation
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.
6 tasks
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.
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.
XMLParsercannot load any per-file resources XML on macOS/LinuxThe resources XML carries
<!DOCTYPE tmres SYSTEM \"resources\\tmres.dtd\">. WithsetValidating(true)the JDK parser tries to resolve that as a URI; the backslash and the relative path mean it fails on non-Windows withno protocol: resources\\tmres.dtd. TheIOExceptionpropagates up toTMUI.openFile, theFileImageends up without aTMFileResources, and the user's bookmarks/palettes silently disappear.Fix:
setValidating(false)plus a no-opEntityResolverthat 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.toXMLkeeps emitting the broken DTD referenceEven 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.
TMViewcomponentResizedlistener can NPE oneditorCanvasThe component listener is registered before
editorCanvasis 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 arevalidate()on the content pane while the frame is still being constructed. Cheap one-line guard.4.
TMUI.openFileleavesFileImageresource-less after a load failureIf 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
mvn package(Java 17)🤖 Generated with Claude Code