Alterações TimeZone.setDefault no JDK6
Acabei de notar que o JDK 6 tem uma abordagem diferente para definir um fuso horário padrão que o JDK5.
Anteriormente, o novo padrão seria armazenado em uma variável local do encadeamento. Com o JDK6 (acabei de revisar a versão 1.6.0.18), a implementação foi alterada, de modo que, se o usuário puder gravar na propriedade "user.timezone" ou se não houver um SecurityManager instalado, o fuso horário mudará para toda a VM! Caso contrário, ocorrerá uma alteração local do encadeamento.
Estou errado? Parece uma mudança drástica, e não consegui encontrar nada na web sobre isso.
Aqui está o código JDK6:
private static boolean hasPermission() {
boolean hasPermission = true;
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
sm.checkPermission(new PropertyPermission("user.timezone", "write"));
} catch (SecurityException e) {
hasPermission = false;
}
}
return hasPermission;
}
/**
* Sets the <code>TimeZone</code> that is
* returned by the <code>getDefault</code> method. If <code>zone</code>
* is null, reset the default to the value it had originally when the
* VM first started.
* @param zone the new default time zone
* @see #getDefault
*/
public static void setDefault(TimeZone zone)
{
if (hasPermission()) {
synchronized (TimeZone.class) {
defaultTimeZone = zone;
defaultZoneTL.set(null);
}
} else {
defaultZoneTL.set(zone);
}
}
enquanto antes (no JDK5) era simplesmente:
/**
* Sets the <code>TimeZone</code> that is
* returned by the <code>getDefault</code> method. If <code>zone</code>
* is null, reset the default to the value it had originally when the
* VM first started.
* @param zone the new default time zone
* @see #getDefault
*/
public static synchronized void setDefault(TimeZone zone)
{
defaultZoneTL.set(zone);
}