Use Locale.ROOT for toLowerCase/toUpperCase calls#61
Open
AlexProgrammerDE wants to merge 3 commits intoExlll:masterfrom
Open
Use Locale.ROOT for toLowerCase/toUpperCase calls#61AlexProgrammerDE wants to merge 3 commits intoExlll:masterfrom
AlexProgrammerDE wants to merge 3 commits intoExlll:masterfrom
Conversation
Fixes locale-sensitive case conversion that can produce unexpected results on systems with certain default locales (e.g. Turkish locale where 'I'.toLowerCase() becomes 'ı' instead of 'i'). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR makes string case conversions locale-independent by updating toLowerCase()/toUpperCase() calls to use Locale.ROOT, preventing behavior differences under non-English default JVM locales (e.g., Turkish) in serializer error messages and environment variable resolution.
Changes:
- Updated serializer exception message formatting to use
toLowerCase(Locale.ROOT). - Updated environment variable key normalization to use
toUpperCase(Locale.ROOT). - Updated related test helper message formatting to match production behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| configlib-core/src/main/java/de/exlll/configlib/Serializers.java | Uses toLowerCase(Locale.ROOT) when building coercion-related exception messages. |
| configlib-core/src/main/java/de/exlll/configlib/RootSerializer.java | Uses toUpperCase(Locale.ROOT) when normalizing env var keys for lookups. |
| configlib-core/src/test/java/de/exlll/configlib/SerializersTest.java | Aligns expected exception message formatting with Locale.ROOT lowercasing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
configlib-core/src/main/java/de/exlll/configlib/Serializers.java
Outdated
Show resolved
Hide resolved
configlib-core/src/test/java/de/exlll/configlib/SerializersTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…t.java Co-authored-by: Copilot <175728472+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.
Summary
toLowerCase()andtoUpperCase()calls withtoLowerCase(Locale.ROOT)/toUpperCase(Locale.ROOT)acrossSerializers.java,RootSerializer.java, andSerializersTest.java.Why This Is Needed
Java's
String.toLowerCase()andString.toUpperCase()without aLocaleargument useLocale.getDefault(), which is derived from the system/JVM locale. This means the same code can produce different results on different machines depending on the OS locale settings.The most well-known problem is with the Turkish locale (
tr_TR), where:Locale.ENGLISH/Locale.ROOTLocale("tr", "TR")"INTEGER".toLowerCase()"integer""ınteger"(dotless ı)"integer".toUpperCase()"INTEGER""İNTEGER"(dotted İ)"I".toLowerCase()"i""ı""i".toUpperCase()"I""İ"Concrete impact in this codebase
Serializers.java: The error message includessourceTypeName.toLowerCase()(e.g., turning"Boolean"into"boolean"for the phrase"boolean-to-string coercion"). On a Turkish-locale system,"Boolean"would become"boolean"correctly, but type names containingI(like"BigInteger") would become"bıgınteger"— a garbled error message.RootSerializer.java: Environment variable names are uppercased withtoUpperCase(). On a Turkish-locale system, a key containing"i"would be converted to"İ"(with a dot above) instead of"I", causing environment variable lookups to silently fail to match the actual env var.Examples of real-world breakage
Locale.ROOTis the correct choice here (rather thanLocale.ENGLISH) because these are programmatic/technical strings, not user-facing text that needs language-specific rules.Locale.ROOTprovides locale-independent behavior, which is exactly what's needed for identifiers, env var names, and type names.Test plan
toLowerCase()/toUpperCase()calls in the codebase🤖 Generated with Claude Code