My System:
System.out.println(Charset.defaultCharset().toString()); //prints windows-1254
System.out.println(Locale.getDefault()); // prints tr_TR
Problem Example:
—
public class LocaleTester {
private String tableName="HI";
@Test
public void toLowercaseTest(){
assertEquals("hi", tableName.toLowerCase());
}
@Test
public void toLowercaseTestWithUsLocale(){
assertEquals("hi", tableName.toLowerCase(new Locale("en", "US")));
}
@Test
public void toLowercaseTestWithTrLocale(){
assertEquals("hi", tableName.toLowerCase(new Locale("tr", "TR")));
}
}
—
toLowercaseTestWithUsLocale passes,
toLowercaseTest & toLowercaseTestWithTrLocale fails:
—
expected: <h > but was: <h[ı] >
Expected :hi
Actual :hı
—
The root of the problem:
Upper case / lower case character mapping is not compatible with English for example:
English
Uppercase - Lowercase
I - i
Turkish
Uppercase - Lowercase
I - ı
İ - i
—
so on the second run, when you search for a table named tablename.toLowerCase() it cannot find the table if it contains a variant of characters that has different mappings than english counterpart.
(I believe) the problem I encountered is only relevant in table name conversions. When I changed tomcat locale to English the problem solved. (Although it is not really a solution because this will bring other problems). Also I didn’t explore full extend of locale problems. My solution proposal is to change tablename.toLowerCase() to tablename.toLowerCase(englishLocale). Of course I may not be aware of different impacts this will cause.