Reputation: 96385
I'm not used to having to take i18n stuff into account. I wrote this method for a Java program:
boolean isWindows()
{
return System.getProperty("os.name").toLowerCase().contains("windows");
}
I need this check in order to provide a workaround for a Windows-specific JVM bug.
It occurred to me this program may need to run on systems that do not have English as the chosen language, is that going to cause this line of code to break?
Maybe I should clarify that I asked this hoping to see what proof people could dredge up (so I feel better about letting this code out into the wild). Answers with links to documentation, experimental evidence, or some kind of supporting rationale get preference.
Upvotes: 1
Views: 429
Reputation: 1994
As Tomasz and Edward said, "os.name" is safe to check with "startWith", but answering "Do the contents of java.lang.System.properties change with locale?", you must notice that, some of properties of System.getProperties may change with locale. Printing properties with different Linux LANGs, I found three properties that changes: "user.country", "user.language" and "sun.jnu.encoding".
Upvotes: 1
Reputation: 340733
Let me get this straight, you are wondering whether OS name (as returned by os.name
property) might be internationalized and contain the word windows in other language?
I would say that for 99% it won't as Microsoft Windows is a trademark (or whatever, IANAL) and is probably not translated and left as-is. However, I looked up the definition of IS_OS_WINDOWS
property in Apache Commons Lang SystemUtils class. After removing all the layers of indirection it all boils down to:
System.getProperty("os.name").startsWith("Windows");
I am not claiming this is a proof, but I tend to believe in such well established libraries.
Upvotes: 3
Reputation: 78673
System.getProperty("os.name").startsWith("Windows")
is safe regardless of locale.
Upvotes: 0