JDK-4654688 : getFlavorsForNative() and getNativesForFlavor() are inconsistent with javadoc
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-03-19
  • Updated: 2017-05-16
  • Resolved: 2003-08-19
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 Availabitlity Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Description

Name: dsR10078			Date: 03/19/2002

###@###.###

The following test case reproduces the problem:
----------------------------------------------------------------------
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.SystemFlavorMap;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        DataFlavor flavor = new DataFlavor("text/plain", "Test DataFlavor");
        SystemFlavorMap flavorMap =
            (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
        List knownFlavors = flavorMap.getFlavorsForNative(null);
        System.out.println("Is " + flavor + " known : " +
                           knownFlavors.contains(flavor));
        System.out.println("Natives for " + flavor + " : " +
                           flavorMap.getNativesForFlavor(flavor)); 
    }
}
----------------------------------------------------------------------
Compile and run the test case.
On Win32 the output is as follows:
----------------------------------------------------------------------
Z:\new_bug>J:\JDK1.4.1-b05\win32\bin\java Test
Is java.awt.datatransfer.DataFlavor[mimetype=text/plain;representationclass=java.io.InputStream;charset=Cp1252] known : false
Natives for java.awt.datatransfer.DataFlavor[mimetype=text/plain;representationclass=java.io.InputStream;charset=Cp1252] : [UNICODE TEXT, TEXT, UniformResourceLocator]
----------------------------------------------------------------------
On Solaris/Linux the output is as follows:
----------------------------------------------------------------------
<das@libox(pts/29).270> /net/archer/jdk-builds/JDK1.4.1-b05/linux/bin/java Test 
Is java.awt.datatransfer.DataFlavor[mimetype=text/plain;representationclass=java.io.InputStream;charset=ISO8859_1] known : false
Natives for java.awt.datatransfer.DataFlavor[mimetype=text/plain;representationclass=java.io.InputStream;charset=ISO8859_1] : [COMPOUND_TEXT, TEXT, STRING]
----------------------------------------------------------------------

SystemFlavorMap.getFlavorsForNative(null) is documented to return 
"all DataFlavors currently known to the data transfer subsystem". 
The javadoc for getNativesForFlavor() specifies that "if the 
specified DataFlavor is previously unknown to the data transfer 
subsystem, then invoking this method will establish a mapping in 
both directions between the specified DataFlavor and an encoded 
version of its MIME type as its native".

In the example above, the created data flavor is not contained in the 
List, returned from SystemFlavorMap.getFlavorsForNative(null), so it 
is unknown to the data transfer subsystem, but on all platforms 
getNativesForFlavor() for this data flavor returns three natives, none 
of them is the encoded version of its MIME type.

This inconsistency exists since this API first appeared in 1.4.0. 
  
###@###.### 2002-03-19
======================================================================

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

WORK AROUND Name: dsR10078 Date: 03/19/2002 ======================================================================
2004-06-11

EVALUATION Here is the evaluation by the responsible engineer, ###@###.### This bug requires an API change. The possible solution would be to modify the javadoc for SystemFlavorMap.getNativesForFlavor() as follows: --- SystemFlavorMap.java Fri Mar 15 17:52:12 2002 *************** *** 558,564 **** * flavor to the underlying native platform. * <p> * If the specified <code>DataFlavor</code> is previously unknown to the ! * data transfer subsystem, then invoking this method will establish a * mapping in both directions between the specified <code>DataFlavor</code> * and an encoded version of its MIME type as its native. * --- 558,566 ---- * flavor to the underlying native platform. * <p> * If the specified <code>DataFlavor</code> is previously unknown to the ! * data transfer subsystem and this <code>DataFlavor</code> cannot be ! * translated to any <code>String</code> native currently known to the data ! * transfer subsystem, then invoking this method will establish a * mapping in both directions between the specified <code>DataFlavor</code> * and an encoded version of its MIME type as its native. ###@###.### 2002-05-01
2002-05-01