Some issues on identifying on Windows

Dmytro Sheyko dmytro_sheyko at
Wed Feb 9 10:25:51 UTC 2011


Maybe it makes sense to use environment variables on Linux (and Solaris) as well in order to minimize failure of "" and "user.home" detection, doesn't it?

As for Windows, many Win32 functions fail when system is shutting down, and GetUserName shouldn't be an exception. But I don't know other conditions till now.

I believe that JVM shouldn't stop working if user name can't be determined because many applications do not need to know it at all.
Actually system properties don't seems very reliable source for those applications that DO need user name. One can easily cheat them by setting env var USERNAME (on Windows)
or just passing in command line explicitly. I think this kind of application needs separate API that provides true system information and better diagnostics
in problematic cases.

As for default value for "" I changed my mind. I think we shouldn't place "" to system properties at all if user name cannot be determined.
(Of course, documenting this behavior well in System.getProperties() javadoc)
It would be easier to handle quite rare problematic cases with following code

    String username = System.getProperty("", fallbackUsernameValue);

than with

    String username = System.getProperty("");
    if (username.equals("?") || username.equals("unknown")) {
        username = fallbackUsernameValue;


Date: Tue, 8 Feb 2011 13:30:19 +0000
From: Alan.Bateman at
To: dmytro_sheyko at
CC: core-libs-dev at
Subject: Re: Some issues on identifying on Windows

  Message body

Dmytro Sheyko wrote:



I noticed following code





     * User name

     * We try to avoid calling GetUserName as it turns out to

     * be surprisingly expensive on NT.  It pulls in an extra

     * 100 K of footprint.



        WCHAR *uname = _wgetenv(L"USERNAME");

        if (uname != NULL && wcslen(uname) > 0) {

            sprops.user_name = _wcsdup(uname);

        } else {

            WCHAR buf[100];

            int buflen = sizeof(buf);

            sprops.user_name =

                GetUserNameW(buf, &buflen) ? _wcsdup(buf) :



Dmytro - I agree this code should be fixed. On the buffer size, my
guess is that it's rare to have a 50+ character username and so it
probably hasn't been an issue.

I think the issue of what to do when the username cannot be determined
is a good question and should be re-examined. Defaulting to "?" or
"unknown" is problematic as some applications need to use the value of
the propety in file names or as a key. We've had a few
reports of problems on Linux where is defaulting to "?". In
the examples that I looked at it was because the 32-bit JDK was being
used on a 64-bit system and the 32-bit libnss_ldap wasn't installed.
Minimally we need to make these types of issues easier to diagnose, and
perhaps look at the implications of having the startup fail if the
username cannot be determined. In the your patch you propose to
standardize on "?" if the username cannot be determined and I just
wonder if there are any genuine conditions where it might fail on
Windows and whether is there might be any existing code depending on
"unknown" (I hope not).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the core-libs-dev mailing list