JDK-4212613 : REGRESSION: java.awt.datatransfer.DataFlavor constructors behavior changed
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.1,1.2.1
  • Priority: P1
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_2.6,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 1999-02-18
  • Updated: 1999-04-16
  • Resolved: 1999-03-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.
Other
1.2.2 1.2.2Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
The  DataFlavor(String) based constructors used to default the class=<javaclass>
param to java.io.DataFlavor if none was specified. This default behavior is
very useful when constructing a simple DataFlavor for an external MIME
content type such as an e-mail attachment etc since such types typically
would not be a DataFlavor, and they would typically be represented as an
InputStream. 

Unfortunately the javadoc clashed with the implementation, and someone 
mindlessly changed the implementation to match the javadoc.

I believe that this fix is inappropriate.



tim.bell@Eng 1999-03-05
An easy way to demonstrate this bug is to use the msgsend.java
program in the javamail 1.1.1/demo directory:

1) cd <wherever>/javamail-1.1.1/demo
2) setenv CLASSPATH <wherever>/mail.jar:<wherever>/activation.jar:.
3) javac msgsend.java
4) java -Djava.compiler=NONE msgsend -s "BugId 4212613" -d user@host < /etc/motd

The output will be:


To: user@host
Subject: BugId 4212613
Exception in thread "main" java.lang.ExceptionInInitializerError: java.lang.IllegalArgumentException: no representation class specified for:text/plain
        at java.awt.datatransfer.DataFlavor.initialize(DataFlavor.java:335)
        at java.awt.datatransfer.DataFlavor.<init>(DataFlavor.java:250)
        at javax.activation.ActivationDataFlavor.<init>(ActivationDataFlavor.java:77)
        at com.sun.mail.handlers.text_plain.<clinit>(text_plain.java:33)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:124)
        at javax.activation.MailcapCommandMap.createDataContentHandler(MailcapCommandMap.java:368)
        at javax.activation.DataHandler.getDataContentHandler(DataHandler.java:617)
        at javax.activation.DataHandler.getInputStream(DataHandler.java:241)
        at javax.activation.DataHandlerDataSource.getInputStream(DataHandler.java:701)
        at javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:99)
        at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:946)
        at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1605)
        at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1586)
        at javax.mail.Transport.send(Transport.java:72)
        at msgsend.<init>(msgsend.java:139)
        at msgsend.main(msgsend.java:29)

This was observed using build J:

% java -version ; java -fullversion
java version "1.2.1"
Classic VM (build JDK-1.2.1-J, green threads, sunwjit)
java full version "JDK-1.2.1-J"

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

EVALUATION ###@###.### 03/05/99 This is caused by the fix for 4173707: DataFlavor(String) doesn't throw IllegalArgumentException It is reasonable to backout this fix and change the documentation later in 1.3 to make doc and implementation consistent again.
11-06-2004

WORK AROUND change constructor string to include class.
11-06-2004

SUGGESTED FIX back out this change immediately ###@###.### 03/05/99 ------- DataFlavor.java ------- *** /tmp/da003Ii Thu Jan 1 03:00:00 1970 --- DataFlavor.java Mon Mar 1 17:01:43 1999 *************** *** 277,283 **** public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException { super(); try { - oldstyle = true; initialize(mimeType, humanPresentableName, classLoader); } catch (MimeTypeParseException mtpe) { throw new IllegalArgumentException("failed to parse:" + mimeType); --- 277,282 ---- *************** *** 304,311 **** } } - private boolean oldstyle = false; - /** * common initialization code called from various constructors. * --- 303,308 ---- *************** *** 325,339 **** String rcn = getParameter("class"); if (rcn == null) { ! if (oldstyle) { ! if ("application/x-java-serialized-object".equals(this.mimeType.getBaseType())) ! throw new IllegalArgumentException("no representation class specified for:" + mimeType); ! else ! representationClass = java.io.InputStream.class; // default ! } else { ! throw new IllegalArgumentException("no representation class specified for:" + mimeType); ! } } else { // got a class name representationClass = DataFlavor.tryToLoadClass(rcn, classLoader); } --- 322,332 ---- String rcn = getParameter("class"); if (rcn == null) { ! if ("application/x-java-serialized-object".equals(this.mimeType.getBaseType())) ! throw new IllegalArgumentException("no representation class specified for:" + mimeType); ! else ! representationClass = java.io.InputStream.class; // default } else { // got a class name representationClass = DataFlavor.tryToLoadClass(rcn, classLoader); }
11-06-2004