-
Notifications
You must be signed in to change notification settings - Fork 24
Use Locale.ROOT for toLowerCase/toUpperCase calls #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Locale.ROOT for toLowerCase/toUpperCase calls #61
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
|
Hi @AlexProgrammerDE, thanks your for contribution. 👍 Changing the locale looks like a breaking change to me which I why I will not accept this PR as is. The correct, non-breaking way to implement this is to make the locale configurable via |
|
Hi, I don't think this can break any major code. This simply updates exception messages to look correct and also fixes environment variables for turkish minecraft servers. Who would want environment variables to work on english servers but fail to apply on turkish servers? |
|
Yeah, you are probably (and hopefully) right. I just tested to set |
|
Thank you! <3 |
|
I've released version 4.8.1. Thanks again for the contribution! |
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