United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6627362 : javac generates code that uses array.clone, which is not available on JavaCard

Details
Type:
Enhancement
Submit Date:
2007-11-08
Status:
Closed
Updated Date:
2011-05-18
Project Name:
JDK
Resolved Date:
2011-05-18
Component:
tools
OS:
generic
Sub-Component:
javac
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Backport:
Relates:
Relates:
Relates:

Sub Tasks

Description
JavaCard does not support clone() for arrays, which causes problems for enums. 
It would be nice if javac could generate different code for the values() method that does not rely on array.clone().

For example, replace the following:
    public static Color[] values() {
        return (Color[]) $VALUES.clone();
    }

with this:
    public static Color[] values() {
      Color[] copy = new Color[$VALUES.length];
      System.arraycopy($VALUES, 0, 
                       copy, 0, 
                       $VALUES.length);
      return copy;
    }

                                    

Comments
EVALUATION

Could make the alternate code be dependent on whether java.lang.Cloneable is on the bootclasspath.
                                     
2007-11-08
EVALUATION

Per 6627366, it looks like Cloneable and Serializable have to be on the class path if a program uses Java arrays. Therefore, it is proposed to refine the test of whether or not to use clone() to 
- Cloneable not found
- Cloneable not public
                                     
2007-11-08



Hardware and Software, Engineered to Work Together