8162563: Fix double checked locking in System.console()
authormartin
Tue, 26 Jul 2016 15:41:40 -0700
changeset 39826 5dba95a26226
parent 39825 6441823cea46
child 39827 21a9b8df49f5
8162563: Fix double checked locking in System.console() Reviewed-by: rriggs, sherman
jdk/src/java.base/share/classes/java/lang/System.java
--- a/jdk/src/java.base/share/classes/java/lang/System.java	Tue Jul 26 12:56:26 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/System.java	Tue Jul 26 15:41:40 2016 -0700
@@ -236,10 +236,12 @@
      * @since   1.6
      */
      public static Console console() {
-         Console c = cons;
-         if (c == null) {
+         Console c;
+         if ((c = cons) == null) {
              synchronized (System.class) {
-                 cons = c = SharedSecrets.getJavaIOAccess().console();
+                 if ((c = cons) == null) {
+                     cons = c = SharedSecrets.getJavaIOAccess().console();
+                 }
              }
          }
          return c;