JDK-6628737 : Specification of wrapper class valueOf static factories should require caching of boxing range
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-11-12
  • Updated: 2017-05-16
  • Resolved: 2009-07-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b66Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The static factory methods Integer.valueOf(int), Long.valueOf(long), etc. were introduced in JDK 5 for javac to implement the caching behavior required by the autoboxing specification.  While the specification of those methods say they might cache, they do not require caching of the ranges in question.  The specification should be updating to require caching of the boxing range, but clearly state that caching outside of that range may or may not happen.

Comments
SUGGESTED FIX # http://hg.openjdk.java.net/jdk7/tl/jdk/raw-rev/ae60bb671e54 # HG changeset patch # User darcy # Date 1247167890 25200 # Node ID ae60bb671e545d1c72e5522f8bdf15690b2522ec # Parent d3a08f8c3c86d0c01688989234c5f5d9c2b97c20 6628737: Specification of wrapper class valueOf static factories should require caching Reviewed-by: mr --- a/src/share/classes/java/lang/Byte.java Wed Jul 08 09:12:17 2009 -0700 +++ b/src/share/classes/java/lang/Byte.java Thu Jul 09 12:31:30 2009 -0700 @@ -90,8 +90,8 @@ public final class Byte extends Number i * If a new {@code Byte} instance is not required, this method * should generally be used in preference to the constructor * {@link #Byte(byte)}, as this method is likely to yield - * significantly better space and time performance by caching - * frequently requested values. + * significantly better space and time performance since + * all byte values are cached. * * @param b a byte value. * @return a {@code Byte} instance representing {@code b}. --- a/src/share/classes/java/lang/Character.java Wed Jul 08 09:12:17 2009 -0700 +++ b/src/share/classes/java/lang/Character.java Thu Jul 09 12:31:30 2009 -0700 @@ -2571,6 +2571,10 @@ class Character extends Object implement * significantly better space and time performance by caching * frequently requested values. * + * This method will always cache values in the range '&#92;u0000' + * to '&#92;u007f'", inclusive, and may cache other values outside + * of this range. + * * @param c a char value. * @return a <tt>Character</tt> instance representing <tt>c</tt>. * @since 1.5 --- a/src/share/classes/java/lang/Integer.java Wed Jul 08 09:12:17 2009 -0700 +++ b/src/share/classes/java/lang/Integer.java Thu Jul 09 12:31:30 2009 -0700 @@ -638,6 +638,9 @@ public final class Integer extends Numbe * to yield significantly better space and time performance by * caching frequently requested values. * + * This method will always cache values in the range -128 to 127, + * inclusive, and may cache other values outside of this range. + * * @param i an {@code int} value. * @return an {@code Integer} instance representing {@code i}. * @since 1.5 --- a/src/share/classes/java/lang/Long.java Wed Jul 08 09:12:17 2009 -0700 +++ b/src/share/classes/java/lang/Long.java Thu Jul 09 12:31:30 2009 -0700 @@ -560,6 +560,11 @@ public final class Long extends Number i * 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. + * * @param l a long value. * @return a {@code Long} instance representing {@code l}. * @since 1.5 --- a/src/share/classes/java/lang/Short.java Wed Jul 08 09:12:17 2009 -0700 +++ b/src/share/classes/java/lang/Short.java Thu Jul 09 12:31:30 2009 -0700 @@ -218,6 +218,9 @@ public final class Short extends Number * {@link #Short(short)}, as this method is likely to yield * significantly better space and time performance by caching * frequently requested values. + * + * This method will always cache values in the range -128 to 127, + * inclusive, and may cache other values outside of this range. * * @param s a short value. * @return a {@code Short} instance representing {@code s}.
09-07-2009

EVALUATION Specification should be amended.
12-11-2007