8162563: Fix double checked locking in System.console()
Reviewed-by: rriggs, sherman
--- 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;