FULL PRODUCT VERSION :
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows server 2003 enterprise edition
A DESCRIPTION OF THE PROBLEM :
In turkish locale when toUpperCase method is called on a string which contains English alphabet small "i", say if the String str = "turkish". and str.toUpperCase() api is called. string is converted something like this "TURK¦SH" . and string comparision fails. because of conversion.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
In my application, I have keys stored in HashMap in toUpperCase. When I try to retrieve the values from HashMap based on string comparision, if key contains alphabet "i" comparision always fails in Turkish locale whereas sameone works in English. To reproduce the problem I have written the following simple java program.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
public class TestStringConversion
{
public static void main(String[] args)
{
HashMap<String,String> hashMap = new HashMap<String,String> (2);
String key1 = "TURKISH";
String key2 = "ENGLISH";
hashMap.put(key1,"turk");
hashMap.put(key2,"eng");
String userChosenLang = "none";
System.out.println("Select from the available options: turkish,english ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String langSelected = null;
try {
langSelected = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read value!");
System.exit(1);
}
Iterator it = hashMap.keySet().iterator();
while(it.hasNext())
{
String key = (String)it.next();
if((langSelected .toUpperCase()).trim().equals(key))
{
userChosenLang = (String)hashMap.get(key);
}
}
System.out.println("User has chosen the following option:"+ userChosenLang);
}
}
If user provides english,turkish inputs in english locale if clause
if((langSelected .toUpperCase()).trim().equals(key))
returns true but in turkish locale it is always returned false.
I have gone through bug id 6208680 and the workaround suggested. But this workaround is too tedious to implement in our project. In future releases of jdk will this issue be taken care?
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
String comparision should work
ACTUAL -
String comparision fails
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
public class TestStringConversion
{
public static void main(String[] args)
{
HashMap<String,String> hashMap = new HashMap<String,String> (2);
String key1 = "TURKISH";
String key2 = "ENGLISH";
hashMap.put(key1,"turk");
hashMap.put(key2,"eng");
String userChosenLang = "none";
System.out.println("Select from the available options: turkish,english ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String langSelected = null;
try {
langSelected = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read value!");
System.exit(1);
}
Iterator it = hashMap.keySet().iterator();
while(it.hasNext())
{
String key = (String)it.next();
if((langSelected .toUpperCase()).trim().equals(key))
{
userChosenLang = (String)hashMap.get(key);
}
}
System.out.println("User has chosen the following option:"+ userChosenLang);
}
}
---------- END SOURCE ----------
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows server 2003 enterprise edition
A DESCRIPTION OF THE PROBLEM :
In turkish locale when toUpperCase method is called on a string which contains English alphabet small "i", say if the String str = "turkish". and str.toUpperCase() api is called. string is converted something like this "TURK¦SH" . and string comparision fails. because of conversion.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
In my application, I have keys stored in HashMap in toUpperCase. When I try to retrieve the values from HashMap based on string comparision, if key contains alphabet "i" comparision always fails in Turkish locale whereas sameone works in English. To reproduce the problem I have written the following simple java program.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
public class TestStringConversion
{
public static void main(String[] args)
{
HashMap<String,String> hashMap = new HashMap<String,String> (2);
String key1 = "TURKISH";
String key2 = "ENGLISH";
hashMap.put(key1,"turk");
hashMap.put(key2,"eng");
String userChosenLang = "none";
System.out.println("Select from the available options: turkish,english ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String langSelected = null;
try {
langSelected = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read value!");
System.exit(1);
}
Iterator it = hashMap.keySet().iterator();
while(it.hasNext())
{
String key = (String)it.next();
if((langSelected .toUpperCase()).trim().equals(key))
{
userChosenLang = (String)hashMap.get(key);
}
}
System.out.println("User has chosen the following option:"+ userChosenLang);
}
}
If user provides english,turkish inputs in english locale if clause
if((langSelected .toUpperCase()).trim().equals(key))
returns true but in turkish locale it is always returned false.
I have gone through bug id 6208680 and the workaround suggested. But this workaround is too tedious to implement in our project. In future releases of jdk will this issue be taken care?
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
String comparision should work
ACTUAL -
String comparision fails
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
public class TestStringConversion
{
public static void main(String[] args)
{
HashMap<String,String> hashMap = new HashMap<String,String> (2);
String key1 = "TURKISH";
String key2 = "ENGLISH";
hashMap.put(key1,"turk");
hashMap.put(key2,"eng");
String userChosenLang = "none";
System.out.println("Select from the available options: turkish,english ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String langSelected = null;
try {
langSelected = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read value!");
System.exit(1);
}
Iterator it = hashMap.keySet().iterator();
while(it.hasNext())
{
String key = (String)it.next();
if((langSelected .toUpperCase()).trim().equals(key))
{
userChosenLang = (String)hashMap.get(key);
}
}
System.out.println("User has chosen the following option:"+ userChosenLang);
}
}
---------- END SOURCE ----------