• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Warning with String.toLowerCase()

 
Ranch Hand
Posts: 50
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I use string.toLowerCase() I get the warning (in eclipse): "Implicitly using the default locale is a common source of bugs: Use toLowerCase(Locale) instead". Could someone explain this in clearer words and how to fix the problem (I have no experience with Locales). Thanks
 
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't call it a common source of bugs myself. Here's an example of the sort of bug which might occur:

If you had the letter "I" then you would expect toLowerCase() to convert it to "i", right? However if you ran your code in the Turkish locale, you would be using the rules which Turkish uses, namely to produce the "dotless I" like this: "ı". (You can read about that here: Dotted and dotless I.)

You may or may not consider that to be a bug. There are three possibilities:

(1) You want I to be converted to ı when your program is run in the Turkish locale. In this case, leave your code as it is, using the system's default locale.

(2) You want I to be converted to i no matter what locale is the system's default. In this case, pick a suitable locale and use that as the parameter suggested by the message.

(3) You don't care what happens because you don't expect your program to be run by anybody except you. In this case ignore the message.

For background information, here's a link to the relevant Oracle tutorial: Lesson: Setting the Locale.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher McKay wrote:Could someone explain this in clearer words and how to fix the problem (I have no experience with Locales). Thanks


I'm not quite sure what to add to Paul's excellent post, except to say that UK English isn't used by everybody, in the same way that 9/11 only means September the 11th to Americans because that's the way they write their dates.

Winston
 
Christopher McKay
Ranch Hand
Posts: 50
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I wouldn't call it a common source of bugs myself. Here's an example of the sort of bug which might occur:

If you had the letter "I" then you would expect toLowerCase() to convert it to "i", right? However if you ran your code in the Turkish locale, you would be using the rules which Turkish uses, namely to produce the "dotless I" like this: "ı". (You can read about that here: Dotted and dotless I.)

You may or may not consider that to be a bug. There are three possibilities:

(1) You want I to be converted to ı when your program is run in the Turkish locale. In this case, leave your code as it is, using the system's default locale.

(2) You want I to be converted to i no matter what locale is the system's default. In this case, pick a suitable locale and use that as the parameter suggested by the message.

(3) You don't care what happens because you don't expect your program to be run by anybody except you. In this case ignore the message.

For background information, here's a link to the relevant Oracle tutorial: Lesson: Setting the Locale.



Thank you both for such detailed responses :)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic