Je viens de remarquer que JDK 6 a une approche différente pour définir un TimeZone par défaut que JDK5.TimeZone.setDefault changements dans JDK6
Auparavant, la nouvelle valeur par défaut serait stockée dans une variable locale. Avec JDK6 (je viens de passer en revue 1.6.0.18) l'implémentation a changé, de sorte que si l'utilisateur peut écrire dans la propriété "user.timezone", ou si SecurityManager n'est pas installé, le fuseau horaire change à l'échelle de VM! Sinon, une modification locale du thread se produit.
Je me trompe? Cela semble être un changement radical, et je n'ai rien trouvé sur le web à ce sujet.
Voici le code 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);
}
}
avant tout (en JDK5), il était tout simplement:
/**
* 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);
}