• Post Reply Bookmark Topic Watch Topic
  • New Topic

Warning with String.toLowerCase()  RSS feed

 
Christopher McKay
Ranch Hand
Posts: 50
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Posts: 22834
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 3
  • Mark post as helpful
  • send pies
  • 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.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 :)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!