fix: stop the install-root search from adopting unrelated directories - #7704
Open
Vest wants to merge 1 commit into
Open
fix: stop the install-root search from adopting unrelated directories#7704Vest wants to merge 1 commit into
Vest wants to merge 1 commit into
Conversation
findInstallRoot climbed from java.home to the filesystem root and, at every ancestor, tested every child directory for a data + system pair. Any unrelated directory that happened to hold both was adopted as the install root, so a checkout left under /tmp hijacked the result and made the two negative findInstallRoot tests fail for reasons that had nothing to do with the code under test. On a normal install the walk also reached /usr and /, where a stray match would silently repoint PCGen's bundled data. The search now only accepts an ancestor itself or that ancestor's "app" subdirectory, which is what jpackage creates beside "runtime", and the climb is bounded so it cannot reach /usr or /. All four packaged layouts still resolve. The starting path is canonicalized as well. Path.getParent is purely lexical, so a symlinked java.home previously yielded the link's textual ancestors rather than the real ones. The result is memoised: java.home is fixed for the life of the JVM, while every @-prefixed path expansion asked for the install root and re-ran the filesystem walk. Adds regression tests for the unrelated-sibling case, the app-versus-decoy preference, a symlinked java.home and the depth bound. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Problem
ConfigurationSettings.findInstallRootlocates PCGen's bundled data by climbing fromjava.home. It climbed to the filesystem root and, at every ancestor, tested every child directory for adata+systempair:Any unrelated directory holding both markers is adopted as the install root.
On a normal Linux install
java.homeis something like/usr/lib/jvm/<jdk>, so the walk scans the children of/usrand/. A stray match there would silently repoint PCGen's bundled data. The walk also re-ran on every lookup (see below).The same flaw makes two unit tests environment-dependent:
findInstallRoot_should_beEmpty_when_noDataFoundfindInstallRoot_should_requireBothMarkers_when_onlyDataPresentBoth use
@TempDir, which on Linux lives under/tmp. Any PCGen checkout elsewhere in/tmphasdata/andsystem/at its root, is found as a sibling, and both "should be empty" assertions fail — unrelated to the code under test.Causation confirmed on an unpatched checkout, with only
/tmpdiffering between runs:/tmpcontentsdata+systemdirectory/tmp/decoy/{data,system}Changes
appsubdirectory — the directory jpackage creates besideruntime— rather than every child of every ancestor. All existing layouts (macOS bundle, Linux image, Windows image, data abovejava.home) still resolve./usror/from a deeply nestedjava.home.Path.getParent()is purely lexical, so a symlinkedjava.homeyielded the link's textual ancestors instead of the real ones. Falls back to the normalized absolute path if the real path cannot be resolved.java.homeis fixed for the life of the JVM, but every@-prefixed path expansion calledgetInstallRoot()and repeated the filesystem walk.Tests
Four regression tests added to
ConfigurationSettingsTest(14 -> 18 tests):appis preferred over a decoy siblingjava.homeresolves correctlyVerified on macOS (full unit suite: 17,158 tests, 0 failures) and on Linux, where the previously failing scenario was reproduced with the decoy directory deliberately in place and now reports 18 tests, 0 failures.
Checkstyle output is unchanged; the remaining violations are pre-existing unused imports in files this PR does not touch.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com