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

ActivationDataFlavor implements Externalizable without public no-arg constructor

XMLWordPrintable

    • In Review
    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin Wessels-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64

      But I think all OSes are affected.

      A DESCRIPTION OF THE PROBLEM :
      Externalizable says:

      When an Externalizable object is reconstructed, an instance is created using the public no-arg constructor, then the readExternal method called. Serializable objects are restored by reading them from an ObjectInputStream.

      But the ActivationDataFlavor does not have a public no-arg constructor. Which results in errors when trying to read from an ObjectInputStream.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to deserialize an ActivationDataFlavor object and see that it works/fails.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect that deserialization of the object works so that my example class would output:

      This should say true: true
      ACTUAL -
      Exception in thread "main" java.io.InvalidClassException: javax.activation.ActivationDataFlavor; no valid constructor
      at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:150)
      at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:768)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
      at ActivationDataFlavorBug.main(ActivationDataFlavorBug.java:23)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.ObjectInputStream;
      import java.io.ObjectOutputStream;

      import javax.activation.ActivationDataFlavor;

      public class ActivationDataFlavorBug {
        public static void main(String[] args) throws Exception {
          File tempFile = null;
          try {
            tempFile = File.createTempFile("activationDataFlavorBug", "outputStream");
            ActivationDataFlavor activationDataFlavor = new ActivationDataFlavor("application/text", "text");
            FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
            objectOutputStream.writeObject(activationDataFlavor);
            objectOutputStream.close();
            fileOutputStream.close();
            FileInputStream fileInputStream = new FileInputStream(tempFile);
            ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
            Object readObject = objectInputStream.readObject();
            System.out.println("This should say true: " + (readObject instanceof ActivationDataFlavor));
            objectInputStream.close();
            fileInputStream.close();
          } finally {
            if (tempFile != null && tempFile.exists()) {
              tempFile.delete();
            }
          }
        }
      }

      ---------- END SOURCE ----------

            rkannathpari Renjith Kannath Pariyangad
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: