Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8202231

For boxing conversion javac uses Long.valueOf which does not guarantee caching according to its javadoc

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 11
    • core-libs
    • None
    • behavioral
    • minimal
    • Formally require long-standing implementation behavior.
    • Java API
    • SE

      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}.

            darcy Joe Darcy
            webbuggrp Webbug Group
            Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: