JDK-4752224 : Cannot create DataFlavor for array class type, of another mime than serialized.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2002-09-24
  • Updated: 2002-09-26
  • Resolved: 2002-09-26
Related Reports
Relates :  
Relates :  
Description
There is no way how to create DataFlavor for array class type object, with another mime type than application/x-java-serialized-object.

I guess I already filled a bug, about more convenient constructor allowing to specify representation class also for other mime types like: application/x-java-jvm-local-objectref.

I used trick which works for non-array classes, i.e.:

new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; class=java.lang.Object", null);

but the same tactic doesn't work for array type:
new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; class=[Ljava.lang.Object;", null)

where the last semicolon (;) which is necessary to specify the class name for array types is always trimmed in mime type parsing, thus it leads to ClassNotFoundException when constructing such DataFlavor.

Comments
EVALUATION Name: agR10216 Date: 09/26/2002 I have run the following test case with the build 1.4.2-beta-b02 and with the build 1.4.0-b92 ---------------------BEGIN SOURCE----------------------------------- import java.awt.datatransfer.DataFlavor; public class CreationDataFlavorTest { public static void main(String[] args) { try { new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; java.lang.Object", null); } catch (Exception e) { e.printStackTrace(); } try { new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; [Ljava.lang.Object;", null); } catch (Exception e) { e.printStackTrace(); } } } ---------------------END SOURCE-------------------------------------- and got the following output (the results for these 2 builds are the same except for some line numbers) ---------------------BEGIN OUTPUT------------------------------------ java.lang.StringIndexOutOfBoundsException: String index out of range: 18 at java.lang.String.charAt(String.java:460) at java.awt.datatransfer.MimeTypeParameterList.parse(MimeTypeParameterList.java:124) at java.awt.datatransfer.MimeTypeParameterList.<init>(MimeTypeParameterList.java:39) at java.awt.datatransfer.MimeType.parse(MimeType.java:147) at java.awt.datatransfer.MimeType.<init>(MimeType.java:47) at java.awt.datatransfer.DataFlavor.initialize(DataFlavor.java:359) at java.awt.datatransfer.DataFlavor.<init>(DataFlavor.java:278) at CreationDataFlavorTest.main(CreationDataFlavorTest.java:6) java.lang.IllegalArgumentException: failed to parse:application/x-java-jvm-local-objectref; [Ljava.lang.Object; at java.awt.datatransfer.DataFlavor.<init>(DataFlavor.java:280) at CreationDataFlavorTest.main(CreationDataFlavorTest.java:12) ---------------------END OUTPUT-------------------------------------- There is no any pair name=value (such as 'class=java.lang.Object') in the MIME types, and it causes the exceptions to be thrown. I observe some inconsistency with the first exception, but it seems to me that the submitter did not mean this. I guess that submitter has provided an incomplete description. ###@###.### 2002-09-26 ====================================================================== Name: agR10216 Date: 09/26/2002 Due to the revised description the test case becomes as follows ---------------------BEGIN SOURCE----------------------------------- import java.awt.datatransfer.DataFlavor; public class CreationDataFlavorTest { public static void main(String[] args) { try { new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; class=java.lang.Object", null); } catch (Exception e) { e.printStackTrace(); } try { new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; class=[Ljava.lang.Object;", null); } catch (Exception e) { e.printStackTrace(); } } } ---------------------END SOURCE-------------------------------------- and produces the following output ---------------------BEGIN OUTPUT------------------------------------ java.lang.IllegalArgumentException: failed to parse:application/x-java-jvm-local-objectref; class=[Ljava.lang.Object; at java.awt.datatransfer.DataFlavor.<init>(DataFlavor.java:280) at CreationDataFlavorTest.main(CreationDataFlavorTest.java:12) ---------------------END OUTPUT-------------------------------------- The cause of the problem is the same as in the bug 4276926. MIME type parameter value with special characters must be quoted: new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; class=\"[Ljava.lang.Object;\"", null); This is not a bug. ###@###.### 2002-09-26 ======================================================================
26-09-2002