JDK-4900166 : static fields in java.lang wrappers for byte sizes (useful for NIO buffers)
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.1.6,1.2.0,1.4.1
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_2000
  • CPU: generic,x86
  • Submitted: 2003-08-01
  • Updated: 2017-05-16
  • Resolved: 2003-08-30
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 Availabitlity Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Duplicate :  
Relates :  
Description

Name: jl125535			Date: 08/01/2003


A DESCRIPTION OF THE REQUEST :
Please add public static int fields in all primitive wrapper classes that contain the size of the type in bytes.

This is trivial, but it gets annoying once you add your own static fields to classes a few different times.

JUSTIFICATION :
Currently, whenever dealing with ByteBuffers and you need to retrieve primitive types using their absolute position within the Buffer, you always need to have your own fields in your class with the size of each primitive type in bytes. While this is not a terrible hardship, it would be simpler, much more elegant, and logical for each primitive wrapper to have constant fields available so that it is immediately apparent what you're up to.

EXPECTED VERSUS ACTUAL BEHAVIOR :
When retrieving data from some buffer, for instance one you have received from a DatagramChannel, and you know the data is stored like this:

a short with the message type
a long with the timestamp
two ints with data

and if you want to retrieve your data using absolute positioning, it seems reasonable to be able retreive it like this:

short type = buffer.getShort(0 * Short.SIZE);
long timeStampe = buffer.getShort(Short.SIZE);
int firstData = buffer.getShort(Short.SIZE + Long.SIZE);
int secondData = buffer.getShort(Short.SIZE + Long.SIZE + Integer.SIZE);
You define your own static fields.
    

CUSTOMER SUBMITTED WORKAROUND :
Define your own static variables, or use relative reading (you can store the initial position and then put the 'cursor' back there when you're done).
(Incident Review ID: 182352) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b18
2004-06-14

SUGGESTED FIX src/share/classes/java/lang>sccs sccsdiff -r1.85 -r1.86 Float.java ------- Float.java ------- 71a72,78 > * The number of bits used to represent a <tt>float</tt> value. > * > * @since 1.5 > */ > public static final int SIZE = 32; > > /** 753,757c760,761 < * This ensures that <code>Float.compareTo(Object)</code> (which < * forwards its behavior to this method) obeys the general < * contract for <code>Comparable.compareTo</code>, and that the < * <i>natural order</i> on <code>Float</code>s is <i>consistent < * with equals</i>. --- > * This ensures that the <i>natural ordering</i> of <tt>Float</tt> > * objects imposed by this method is <i>consistent with equals</i>. src/share/classes/java/lang>sccs sccsdiff -r1.86 -r1.87 Double.java ------- Double.java ------- 71a72,78 > * The number of bits used to represent a <tt>double</tt> value. > * > * @since 1.5 > */ > public static final int SIZE = 64; > > /** 851,854c858,859 < * This ensures that <code>Double.compareTo(Object)</code> (which < * forwards its behavior to this method) obeys the general < * contract for <code>Comparable.compareTo</code>, and that the < * <i>natural order</i> on <code>Double</code>s is <i>consistent --- > * This ensures that the <i>natural ordering</i> of > * <tt>Double</tt> objects imposed by this method is <i>consistent 867d871 < * @see Comparable#compareTo(Object) ###@###.### 2003-08-20
2003-08-20

EVALUATION Bug 4495754 Add library support for common bit manipulation operations includes a SIZE fields, in bits, for the primitive types other than float and double. Simliar fields could be added to Float and Double. ###@###.### 2003-08-05
2003-08-05