Scrivio Interview library
DebuggingFoundations7 min read · updated 12 November 2026

A service checks permissions with if (header.toUpperCase().equals("TITLE")). It works everywhere except on a server whose default locale is Turkish (tr-TR), where the check fails. Explain why and how to fix this and similar bugs.

toUpperCase() without an argument uses the JVM's default locale, and in Turkish the lower-case dotted i becomes a capital I with a dot, U+0130, not the plain I, so "title".toUpperCase() on a tr-TR server gives a string that looks like TITLE but is not equal to it. For identifiers, protocol keywords and keys we use toUpperCase(Locale.ROOT) or equalsIgnoreCase(), and we keep the user's locale for text shown to people. The same default-locale trap affects String.format, number parsing and date formatting, so we pass a Locale explicitly and run tests with a Turkish locale to catch these bugs.

Why this question is asked

This bug is famous because it shows up only on certain servers and looks impossible at first: the code is correct, the input is correct, and the comparison fails. It has broken permission checks, enum lookups, SQL keyword handling and even parts of well-known frameworks over the years. Interviewers ask about it to see whether we understand that some String methods depend on hidden global state, the default locale. In this answer, we will reproduce the failure, see why Turkish behaves differently, fix the check, and then look at the wider family of default-locale bugs and how to catch them before production.

1Reproducing the Failure

A Locale tells Java the language and region conventions to use, such as how to change letter case or write numbers. Methods that take no Locale use the JVM's default, which comes from the operating system or from the user.language and user.country system properties when the JVM starts. We can reproduce the server's setup by changing the default.

Java
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
String header = "title";
String upper = header.toUpperCase(); // looks like TITLE
upper.equals("TITLE"); // false
(int) upper.charAt(1); // 304, which is U+0130, capital I with dot above
header.toUpperCase(Locale.ROOT).equals("TITLE"); // true
"TITLE".equalsIgnoreCase(header); // true, even with the Turkish default

Notice that the strings print almost the same, and in many fonts the dot is easy to miss. The difference is one character, at index 1, and that is enough for equals() to return false. So the permission check fails on exactly the servers whose default locale is Turkish, while every developer laptop works.

2Why Turkish Is Different

English has one letter i with two forms, i and I. Turkish has two separate letters: a dotted i, whose capital keeps the dot, and a dotless one, whose lower-case form has no dot. Turkish case rules therefore pair the dotted lower-case i with the dotted capital, U+0130, and the plain capital I with the dotless lower-case i, U+0131. When Java converts case with a Turkish locale, it follows those rules, which is correct for Turkish text and wrong for an English keyword.

Case mapping of the letter i
CharacterUpper case, Locale.ROOTUpper case, TurkishLower case, Turkish
i (U+0069)I (U+0049)dotted capital I (U+0130)i
I (U+0049)IIdotless i (U+0131)
dotted capital I (U+0130)itselfitselfi
dotless i (U+0131)IIitself
Turkish keeps the dot when changing case, so i and I are no longer a pair.

3Fixing the Check

The header value is a protocol keyword, not human text, so its case must never depend on where the server runs. There are two correct fixes. We can pass Locale.ROOT, the neutral locale whose rules are the same everywhere, to every case conversion. Or, for a comparison, we can use equalsIgnoreCase(), which compares one character at a time with locale-independent rules.

Java
if (header.equalsIgnoreCase("TITLE")) { ... } // clear and locale-independent
if (header.toUpperCase(Locale.ROOT).equals("TITLE")) { ... } // also correct
Role role = Role.valueOf(input.toUpperCase()); // breaks on tr-TR for ADMIN, EDIT, ...
Role role = Role.valueOf(input.toUpperCase(Locale.ROOT)); // correct

Enum lookups are the most common real-world victim, because enum names are usually written in upper case and the input usually is not. Any value containing an i is affected, and the Turkish problem also runs in reverse: "TITLE".toLowerCase() on a Turkish server gives a dotless i, so lower-casing keys before a map lookup fails too.

4The User's Locale Is Only for Human Text

The general rule behind the fix is to separate two kinds of strings. Machine-readable values, such as identifiers, header names, enum names, JSON keys, file extensions and SQL keywords, must be processed with Locale.ROOT or locale-independent methods, because the program reads them and they must mean the same thing everywhere. Text that a person reads, such as a name in a greeting or a title in a report, should be processed with that person's Locale, which we get from their account or request, never from the server's default. In neither case is the server's default locale the right answer, which is why many teams treat any call that silently uses it as a bug.

5The Same Bug in Formatting and Parsing

Case conversion is only one method that reads the default locale. String.format, NumberFormat, DateTimeFormatter.ofPattern without a Locale and the old SimpleDateFormat all do the same. On a server with a German or Turkish default, numbers get a comma as the decimal separator, and on some locales even the digits themselves change.

Java
Locale.setDefault(Locale.GERMANY);
String.format("%.2f", 3.5); // 3,50 breaks a CSV or a JSON value
String.format(Locale.ROOT, "%.2f", 3.5); // 3.50
NumberFormat.getInstance().parse("3.50"); // 350 with a German default: the dot is a grouping separator
Double.parseDouble("3.50"); // 3.5, always: parseDouble ignores locale
DateTimeFormatter.ofPattern("d MMM", Locale.ROOT); // month names fixed, not taken from the server

So any value we write for another program uses Locale.ROOT or a fixed, locale-free format such as ISO 8601 for dates. Some teams also set the JVM default locale explicitly at startup, but that only hides the problem on one server; passing the Locale in the code is the real fix.

6Catching These Bugs Before Production

These bugs survive because development machines use English. The cheapest protection is to run the test suite once with a Turkish default, for example by adding -Duser.language=tr -Duser.country=TR to the argLine of Maven Surefire or the jvmArgs of Gradle's test task in a CI job. Any test that compares keywords will then fail on a laptop instead of in production. Static analysis adds a second net: SpotBugs, Sonar and the forbidden-apis build plugin can all flag toUpperCase(), toLowerCase() and String.format() calls that do not pass a Locale, so the rule is enforced on every new line of code.

7Follow-up questions

Which other languages have special case mapping rules?

Azerbaijani has the same dotted and dotless i as Turkish, and Java treats it the same way. Lithuanian keeps a dot above the i when it is combined with accents in lower case. Greek has a special final form of sigma when lower-casing at the end of a word, which Java's toLowerCase handles by looking at the context. German has the sharp s, which becomes SS in upper case, so the upper-case string is longer than the original, and that happens in every locale. The JDK's String.toUpperCase and toLowerCase documentation lists the locale-sensitive cases, and they are another reason never to assume that a case change keeps the same length or characters.

Is equalsIgnoreCase always safe for keywords?

It is locale-independent, so the Turkish default cannot break it, and for ASCII keywords it is exactly what we want. Its limits show only with characters whose case mapping changes length, such as the German sharp s, which it compares one character at a time and cannot match against SS. For keywords and identifiers that is irrelevant, since they are ASCII. For human text, a case-insensitive comparison should use a Collator with the user's locale at the right strength.

Should we just set the default locale of the JVM to English?

It helps as a safety net, for example with -Duser.language=en in the container image, but it is not a fix. Libraries, tests and other environments may run with a different default, and code that relies on the setting breaks the moment it is reused somewhere else. The code itself should state the Locale it needs, Locale.ROOT for machine values and the user's Locale for human text.

8Conclusion

In this answer, we saw that toUpperCase() without arguments uses the JVM's default locale and that Turkish maps the dotted i to the dotted capital U+0130, so the check against TITLE fails only on tr-TR servers. We fixed it with equalsIgnoreCase or toUpperCase(Locale.ROOT), separated machine-readable values, which use Locale.ROOT, from human text, which uses the user's Locale, saw the same default-locale trap in String.format, number parsing and date formatting, and caught it early with tests under a Turkish locale and static analysis rules.

What to say in the interviewAbout 90 seconds aloud

Open with

toUpperCase with no argument uses the JVM's default locale, and on that server the default is Turkish. Turkish has a dotted and a dotless i as separate letters, so the lower-case i maps to a capital I with a dot above, U+0130, not to the plain I. title in upper case looks like TITLE but has a different character at index 1, so equals returns false, and only on servers with a Turkish default.

Then, if they want more

For anything machine-readable, like header names, identifiers, enum names or keys, I either use equalsIgnoreCase, which is locale-independent, or toUpperCase and toLowerCase with Locale.ROOT. A very common victim is Enum.valueOf with input.toUpperCase, and lowering keys has the reverse problem with the dotless i.

The user's locale should only be used for text people read, and the server's default locale is never the right choice. The same issue hits String.format, NumberFormat and date formatters without a locale: on a German server, format with two decimals gives 3 comma 50, which breaks CSV or JSON, so I pass Locale.ROOT or use ISO formats for data.

To catch these, I run the test suite in CI with -Duser.language=tr and -Duser.country=TR, and turn on a static analysis rule, like SpotBugs or the forbidden-apis plugin, that flags case conversion and format calls without an explicit Locale.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A service checks permissions with if (header.toUpperCase().equals("TITLE")). It works...": https://scrivio-interview-library.netlify.app/java/strings/8719c81462/