Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4410032

JAF DataHandler.getTransferData() incorrect behavior when no DataContentHandler

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.0.2
    • Component/s: other-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.0.2
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Not verified

      Description



      Name: boT120536 Date: 01/30/2001


      [apope@portage cib]$ java -version
      java version "1.3.0beta_refresh"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0beta_refresh-b09)
      Java HotSpot(TM) Client VM (build 1.3.0beta-b07, mixed mode)


      With JAF 1.0.1, when DataHandler.getTransferData() can't find a
      DataContentHandler for a particular MIME type, and the DataHandler was
      created with a DataSource or URL, it's supposed to return an InputStream
      or throw an UnsupportedFlavorException. It throws a NullPointerException
      instead.

      Code demonstrating the problem:

      import java.awt.datatransfer.*;
      import javax.activation.*;

      class Test {

          static class MyDataContentHandlerFactory implements
      DataContentHandlerFactory {
      public DataContentHandler createDataContentHandler( String mimeType ) {
      System.out.println( "DCHFactory: request for " + mimeType + " handler" );
      return null; // don't have one
      }
          }

          static class MyFileTypeMap extends FileTypeMap {
      public String getContentType(java.io.File file) { return
      "application/x-wombat"; }
      public String getContentType(String filename) { return "application/x-wombat";
      }
          }

          class Nombat { }

          static public void main( String args[] ) {
      DataHandler.setDataContentHandlerFactory( new MyDataContentHandlerFactory() );
      FileTypeMap.setDefaultFileTypeMap( new MyFileTypeMap() );
      DataSource ds = new FileDataSource( "Test.java" );
      DataHandler dh = new DataHandler( ds );
      try {
      // According to the DataHandler.getTransferData() documentation, this
      // should return an InputStream:
      Object data = dh.getTransferData(
      new ActivationDataFlavor( java.io.InputStream.class, "application/x-wombat",
      "Wombat" ) );
      System.out.println( data );
      } catch (Exception e) {
      System.err.print("Request for InputStream threw ");
      e.printStackTrace();
      }
      try {
      // According to the DataHandler.getTransferData() documentation, this
      // should throw an UnsupportedFlavorException:
      Object data = dh.getTransferData(
      new ActivationDataFlavor( Nombat.class, "application/not-x-wombat", "Nombat" )
      );
      System.out.println( data );
      } catch (Exception e) {
      System.err.print("Request for Nombat threw ");
      e.printStackTrace();
      }
          }
      }

      Sample output:

      java -classpath .:/export/home/appc/pkg/jaf-1.0.1/activation.jar Test
      DCHFactory: request for application/x-wombat handler
      Request for InputStream threw java.lang.NullPointerException
      at
      javax.activation.DataSourceDataContentHandler.getTransferData(DataHandler.java:746)
      at javax.activation.DataHandler.getTransferData(DataHandler.java:419)
      at Test.main(Test.java:28)
      Request for Nombat threw java.lang.NullPointerException
      at
      javax.activation.DataSourceDataContentHandler.getTransferData(DataHandler.java:746)
      at javax.activation.DataHandler.getTransferData(DataHandler.java:419)
      at Test.main(Test.java:38)
      (Review ID: 109135)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            bshannon Bill Shannon (Inactive)
            Reporter:
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: