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

Attempt to serialize locally transferring data via Windows system clipboard

    Details

    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b81
    • CPU:
      x86
    • OS:
      windows_nt

      Description

      Name: agR10216 Date: 06/03/2002

      ###@###.###
      I reproduced this bug with build 1.4.1-beta-b12.

      I want to transfer an object wrapped in a transferable with
      DataFlavor.javaJVMLocalObjectMimeType data flavor
      via Windows system clipboard within the same JVM.
      In javadoc for DataFlavor.javaJVMLocalObjectMimeType there
      are no specified constraints on a locally transferring object
      with this data flavor.
      But NotSerializableExeption is thrown when contents of
      system clipboard are set and following test case demonstrates it.

      ---------- BEGIN SOURCE ----------
      import java.awt.datatransfer.*;
      import java.awt.*;
      import java.io.*;


      class NotSerializableLocalTransferable implements Transferable {
          public final DataFlavor flavor;

          private final DataFlavor[] flavors;

          private final Object data;


          public NotSerializableLocalTransferable(Object data) throws Exception {
              this.data = data;
              flavor = new DataFlavor(
                  DataFlavor.javaJVMLocalObjectMimeType +
                  ";class=" + "\"" + data.getClass().getName() + "\"");
              this.flavors = new DataFlavor[] { flavor };
          }

          public DataFlavor[] getTransferDataFlavors() {
              return (DataFlavor[])flavors.clone();
          }

          public boolean isDataFlavorSupported(DataFlavor flavor) {
              return this.flavor.equals(flavor);
          }

          public Object getTransferData(DataFlavor flavor)
              throws UnsupportedFlavorException
          {
              if (this.flavor.equals(flavor)) {
                  return (Object)data;
              }
              throw new UnsupportedFlavorException(flavor);
          }


          public static void main (String [] args) throws Exception {
              NotSerializableLocalTransferable t = new NotSerializableLocalTransferable(new NotSer());
              Toolkit.getDefaultToolkit().getSystemClipboard().setContents(t, null);
          }
      }


      class NotSer implements Serializable {
          private Object field = new Object(); // not serializable field
      }
      ---------- END SOURCE ----------

      Here is the output of the given test case.
      ---------- BEGIN OUTPUT ----------
      java.io.NotSerializableException: java.lang.Object
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
              at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1330)
              at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1302)
              at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1245)
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
              at sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:1225)
              at sun.awt.windows.WDataTransferer.translateTransferable(WDataTransferer.java:151)
              at sun.awt.windows.WClipboard.setContents(WClipboard.java:79)
              at NotSerializableLocalTransferable.main(NotSerializableLocalTransferable.java:42)
      ---------- END OUTPUT ----------
      ###@###.### 2002-06-03
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                agerasimsunw Alexander Gerasimov (Inactive)
                Reporter:
                agerasimsunw Alexander Gerasimov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: