JDZ6中的TimeZone.setDefault更改

Tom*_*Tom 17 java timezone default jdk1.6 jdk1.5

我刚刚注意到JDK 6设置默认TimeZone的方法与JDK5不同.

以前,新的默认值将存储在线程局部变量中.使用JDK6(我刚刚查看了1.6.0.18),实现已经改变,因此如果用户可以写入"user.timezone"属性,或者如果没有安装SecurityManager,则时区会在整个VM范围内发生变化!否则会发生线程局部更改.

我错了吗?这似乎是一个相当大的变化,我在网上找不到任何关于它的东西.

这是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);
  }
 }
Run Code Online (Sandbox Code Playgroud)

之前(在JDK5中)它只是:

 /**
  * 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);
 }
Run Code Online (Sandbox Code Playgroud)

Tom*_*Tom 13

搜索bug数据库实际上是个不错的主意:)

http://bugs.sun.com/view_bug.do?bug_id=6352812

还有(重新说明):

http://bugs.sun.com/view_bug.do?bug_id=6181786

简介:JDK 1.5是规则的一个例外,JDK 1.6的东西恢复到"正常",根据文档的说法,时区变化是VM范围的.