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

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Formally require long-standing implementation behavior.
    • Interface Kind:
      Java API
    • Scope:
      SE

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: