JDK-4147507 : StringSelection plainTextFlavor returns a StringReader
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.7,1.2.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 1998-06-10
  • Updated: 1999-11-24
  • Resolved: 1999-11-24
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.3.0 kestrelFixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description

Name: rm29839			Date: 06/10/98


The specification for DataFlavor.plainTextFlavor says that
the representation class is input stream.

However, the object returned from a StringSelection
using plainTextFlavor is a StringReader. This leads to all sorts 
of class cast exceptions when performing a D&D.

java.lang.ClassCastException: java.io.StringReader
        at sun.awt.windows.WDragSourceContextPeer.convertData(WDragSourc
        at sun.awt.windows.WToolkit.eventLoop(Native Method)
        at sun.awt.windows.WToolkit.run(WToolkit.java:123)
        at java.lang.Thread.run(Thread.java:490)

See class java.awt.DataTransfer.StringSelection 
    public synchronized Object getTransferData(DataFlavor flavor) 
line 68.

Perhaps you need to two different flavors.
(Review ID: 33418)
======================================================================
This is not a DnD bug., it belongs in classes_awt.
larry.cable@Eng 1998-06-10

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

WORK AROUND Name: rpC71689 Date: 05/26/99 ###@###.### 05/26/99 Expect that StringSelection.getTransferData(...) will return a StringReadder and handle this situation. ======================================================================
11-06-2004

EVALUATION Commit to fix. david.mendenhall@eng 1998-12-01 Name: dtC58261 Date: 02/04/99 ###@###.### Method getTransferData is declared to return Object type and in case of plain text flavor now it returns StringReader. But the docs now says that: public static final DataFlavor plainTextFlavor The DataFlavor representing plain text with unicode encoding, where: representationClass = InputStream mimeType = "text/plain; charset=unicode" The problem was introduced by Jeff Dinkins's change - D 1.3 97/01/17 11:41:04 jeff 4 3 00001/00001/00081 COMMENTS: changed StringBufferInputStream to StringReader in getTransferData < return (InputStream) new StringBufferInputStream(data); --- > return new StringReader(data); It's done in such a way because StringBufferInputStream is a deprecated class which does not properly converts characters into bytes; one should use java.io.StringReader instead. The problem is that java.io.Reader (which is a parent class for StringReader) is not a subclass of InputStream that's why ClassCastException occurs. We should fix the spec for DataFlavor.plainTextFlavor which now says that the representation class for plain text data flavor is input stream. Because the change to the code is the right thing to do and we should fix the documentation to reflect it. dpm: In a dotdot release, we're allowed to clarify the spec to match the code, or modify the code to conform to the spec. However, we cannot change the spec if the spec explicitly states something different from the code. So this bug will be fixed in 1.3. ====================================================================== Name: rpC71689 Date: 05/26/99 ###@###.### 05/26/99 Any attempts to fix this bug cause a lot of problems. We can't change the javadoc for DataFlavor.plainTextFlavor because many classes are written using the API according to the current documentation (though they are getting ClassCastExceptions) We also can't change StringSelection back to return InputStream as we can get problems with those who expect current behaviour. I see no reasonable exit from this circle. ====================================================================== Since we cannot find an agreeable solution, I am decommitting this bug from Kestrel. eric.hawkes@eng 1999-05-27 We have agreed to deprecated DataFlavor.plainTextFlavor and StringSelection's support of it. We will not actually change the existing functionality in order to preserve backwards-compatibility. This change was approved by the CCC on 22Nov1999. david.mendenhall@eng 1999-11-23
23-11-1999