changeset 50406:661ef62a6618

8200478: For boxing conversion javac uses Long.valueOf which does not guarantee caching according to its javadoc Reviewed-by: bpb
author darcy
date Wed, 25 Apr 2018 22:12:06 -0700
parents c830e94b5606
children ec2dd30adbc1
files src/java.base/share/classes/java/lang/Long.java test/langtools/tools/javac/boxing/BoxingCaching.java
diffstat 2 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Long.java	Wed Apr 25 14:08:19 2018 -0700
+++ b/src/java.base/share/classes/java/lang/Long.java	Wed Apr 25 22:12:06 2018 -0700
@@ -1164,10 +1164,8 @@
      * significantly better space and time performance by caching
      * frequently requested values.
      *
-     * Note that unlike the {@linkplain Integer#valueOf(int)
-     * corresponding method} in the {@code Integer} class, this method
-     * is <em>not</em> required to cache values within a particular
-     * range.
+     * This method will always cache values in the range -128 to 127,
+     * inclusive, and may cache other values outside of this range.
      *
      * @param  l a long value.
      * @return a {@code Long} instance representing {@code l}.
--- a/test/langtools/tools/javac/boxing/BoxingCaching.java	Wed Apr 25 14:08:19 2018 -0700
+++ b/test/langtools/tools/javac/boxing/BoxingCaching.java	Wed Apr 25 22:12:06 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4990346
+ * @bug 4990346 8200478
  * @summary Verify autoboxed values are cached as required.
  * @author Joseph D. Darcy
  */
@@ -155,7 +155,7 @@
             Long L = (long)(i-128);
             if (L != results[i]) {
                 cached = false;
-                System.err.println("Integer value " + L +
+                System.err.println("Long value " + L +
                                    " is not cached appropriately.");
             }
         }