Some issues on identifying user.name on Windows
Alan Bateman
Alan.Bateman at oracle.com
Wed Feb 9 12:50:04 UTC 2011
Dmytro Sheyko wrote:
> Hi,
>
> Maybe it makes sense to use environment variables on Linux (and
> Solaris) as well in order to minimize failure of "user.name" and
> "user.home" detection, doesn't it?
Yes, I think this makes sense. Typically USER and LOGNAME are set (we
might just need to think about the sudo case).
>
> 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.
The counter argument is that applications that do require it could fail
in unpredictable ways. I've seen a couple of cases but never Windows.
Another suggestion is to emit a warning, something that might be
feasible for debug/fastdebug builds (probably not product because
messages coming from the runtime can cause other problems, and can
confuse tests). Minimally we need something to make it easier to diagnose.
> 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 -Duser.name 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 "user.name" I changed my mind. I think we
> shouldn't place "user.name" to system properties at all if user name
> cannot be determined.
> (Of course, documenting this behavior well in System.getProperties()
> javadoc)
I don't think this is an option because it would break existing code
that assumes user.name is set.
> It would be easier to handle quite rare problematic cases with
> following code
>
> String username = System.getProperty("user.name",
> fallbackUsernameValue);
>
> than with
>
> String username = System.getProperty("user.name");
> if (username.equals("?") || username.equals("unknown")) {
> username = fallbackUsernameValue;
> }
We don't document "?" or "unknown" but it would not surprise me to find
code like this.
Anyway back to your original patch, what would you think about modifying
it so that it throws an exception if GetUserNameW fails rather than
defaulting to "unknown"? You mentioned the "Windows is shutting down"
case (and you may be right on that) but I can't think of any others
except period insufficient resources in which case we'll probably keel
over anyway. We can separate this from the Solaris/Linux changes as
that is the most likely places where it might fail and default to "?" today.
-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20110209/65ad594f/attachment.html>
More information about the core-libs-dev
mailing list