Repository navigation
Os.getOsFamily: return an empty string instead of null - #425
Merged
Merged
Conversation
slachiewicz
marked this pull request as ready for review
September 10, 2026 08:31
elharo
requested changes
Sep 10, 2026
The review asked for assertEquals("", OS_FAMILY) instead of assertNotNull,
but the empty-string fallback cannot be reached on any JVM: File.pathSeparator
is ":" or ";", and the unix and dos families are catch-alls on those
separators, with openvms, mac and netware covering their exclusions.
Asserting a specific family is not stable either, since VALID_FAMILIES is a
HashSet and both os/2 and unix match the os.name the test forces.
isValidFamily(OS_FAMILY) is the strongest assertion that holds on every
platform and it subsumes the null check.
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.
Os.getOsFamily()returnsnullwhen the current OS matches none of the known families, soOs.OS_FAMILYcan be null and every caller has to guard for it. Returning an empty string removes that trap.This matches the direction already taken in #403, where
PathTool.getRelativeFilePathmoved fromnullto""for the no-answer case.The commit is Elliotte Rusty Harold's, cherry-picked from the
fix/os-getosfamily-nullbranch he pushed here on 2026-07-01 and never opened as a PR. Authorship is preserved, and the code is unchanged. Opening it because the fix is finished and 3.5.0 is close; happy to hand it back if he would rather carry it himself.Note for reviewers: this is a behaviour change on a public constant. A caller testing
Os.OS_FAMILY == nullsilently stops matching. In practice the branch is only reachable on an OS none of the families cover, andOsis deprecated in 3.5.0 in favour oforg.apache.commons.lang3.SystemUtils, so the exposure is small -- but it is not zero.Verified:
mvn -B verifyon JDK 17 -> Tests run: 788, Failures: 0, Errors: 0. Spotless clean.This change was created with AI assistance.