JDK-8202231 : For boxing conversion javac uses Long.valueOf which does not guarantee caching according to its javadoc
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 11
  • Submitted: 2018-04-25
  • Updated: 2018-05-09
  • Resolved: 2018-04-26
Related Reports
CSR :  
Description
Summary
-------

Update `Long.valueOf(long)` to require caching of values [-128, 127]. The implementation has always cached in this range and the corresponding `valueOf` methods in other integral wrapper classes have been required to cache in this range too.

Problem
-------

Other parts of the platform rely on `Long.valueOf(long)` to cache, but the method is not required to do that caching.

Solution
--------

Update the specification to require caching.

Specification
-------------

    diff -r f909f09569ca src/java.base/share/classes/java/lang/Long.java
    --- a/src/java.base/share/classes/java/lang/Long.java    Wed Apr 18 21:10:09 2018 -0700
    +++ b/src/java.base/share/classes/java/lang/Long.java    Tue Apr 24 17:25:24 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}.


Comments
Moving to Approved.
26-04-2018