United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-5045358 Open MBeans cannot reference primitive data types or arrays thereof
JDK-5045358 : Open MBeans cannot reference primitive data types or arrays thereof

Details
Type:
Enhancement
Submit Date:
2004-05-11
Status:
Resolved
Updated Date:
2005-05-14
Project Name:
JDK
Resolved Date:
2005-05-14
Component:
core-svc
OS:
generic
Sub-Component:
javax.management
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Relates:
Relates:

Sub Tasks

Description
The set of types that can be referenced by an Open MBean is by design
limited.  It includes the primitive wrapper types such as java.lang.Integer
and java.lang.Boolean.  However, it does not include the primitive types
such as int and boolean.  When the type is just Integer or Boolean there
is no great difference to a client, because reflection treats this the
same as int or boolean anyway.  But when it is Integer[] or Boolean[] it
is inconvenient and inefficient.

The suggested change is to define new constants in the SimpleType class
called PRIMITIVE_INT, PRIMITIVE_BOOLEAN, etc, to complement the existing
constants INTEGER, BOOLEAN, etc.

The serial form of these classes will set a new serializable boolean field
"primitive" to true and will have a type name that is the corresponding
wrapper class, e.g. java.lang.Integer for int.  This will mean that interoperation with JMX API implementations that predate this change will be possible.  Such implementations will ignore this field, so they will see a
java.lang.Integer instead of an int.  This will potentially cause problems
for int[] etc (seen as Integer[]) but not for plain int.

                                    

Comments
EVALUATION

Requires API change so cannot be changed before Mustang.
###@###.### 2004-05-11

Changing SimpleType so it supports primitive types is probably not the best approach.  All we are really interested in is *arrays* of primitive types.  There is no difference between int and Integer when they are the type of an attribute, parameter, or return value.  An int will be wrapped as an Integer anyway since everything is happening through reflection.  On the other hand, there *is* a difference between int[] and Integer[].  int[] is considerably more efficient in space and time, but is not currently expressible as an OpenType.  So the idea would be to extend ArrayType rather than SimpleType such that you can describe int[] etc with it.  For example, we could add a factory method to ArrayType:
    public static ArrayType primitiveArray(Class<?> arrayClass)
or, in its generified form (see 4847959):
    public static ArrayType<T> primitiveArray(Class<T> arrayClass)
Thus, you could obtain an instance of the appropriate Open Type for int[]
using ArrayType.primitiveArray(int[].class).
ArrayType.getElementOpenType() would return SimpleType.INTEGER, so it would
look very like an Integer[], but there would be an additional method
    public boolean isPrimitiveArray()
which would return true for one but not the other.  This would be reflected
in the serial form by a new field
    private boolean primitive;
Previous versions of the API would lack this field so would deserialize
an int[] as an Integer[].  This will often work, for example if arrays
are ready using java.lang.reflect.Array, but will occasionally cause
ClassCastExceptions.  This only applies to "generic" (model-neutral)
clients, since models that use int[] as an Open Type are necessarily
new and existing model-specific clients cannot know those new models.
###@###.### 2004-08-27
                                     
2004-08-27
PUBLIC COMMENTS

Open MBeans can reference java.lang.Integer but not plain int, etc.
                                     
2004-09-01
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mustang


                                     
2004-09-01



Hardware and Software, Engineered to Work Together