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

JEditorPane with HTML content won't serialize under 1.3

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta
    • x86
    • windows_2000



      Name: krC82822 Date: 11/29/2000


      29 Nov 2000, eval1127@eng -- yields:
      java.io.NotSerializableException: javax.swing.text.html.HTML$Tag ...
      see also # 4226914, 4277157.
      Tried removing the <A...></A> tag -- no change.
      Tried inserting explicit <HTML></HTML> -- no change.
      Finally changed to "text/plain" and no HTML tags, and it can be serialized
      and deserialized OK.
      ---------------
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


      Compile and run the following program:


      package ser;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import java.io.*;

      public class SEditorPane extends JEditorPane
      {
        public static void main (String [] args)
        {
          final SEditorPane epane = new SEditorPane();
          final JFrame frame = new JFrame ("save this");
          frame.setContentPane(epane);
          frame.setSize (150,100);
          frame.show();

          JFrame control = new JFrame ("control");
          JButton button = new JButton ("save & restore");
          button.addActionListener (new ActionListener() {
            public void actionPerformed (ActionEvent e)
            { saveAndRestore(frame); }
          });
          control.setContentPane (button);
          control.setBounds(200,200,200,100);
          control.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          control.show();
        }

        public static void saveAndRestore (JFrame frame)
        {
          try {
            ObjectOutputStream oos = new ObjectOutputStream (
              new FileOutputStream ("test.out"));
            oos.writeObject(frame);
            oos.flush();
            oos.close();
          } catch (Exception ex) { ex.printStackTrace(); }

          JFrame frame2 = null;
          try {
            ObjectInputStream ois = new ObjectInputStream (
              new FileInputStream ("test.out"));
            frame2 = (JFrame) ois.readObject();
            ois.close();
          } catch (Exception ex) { ex.printStackTrace(); }
          if (frame2 == null) return;

          Point p = frame2.getLocation();
          p.translate (30,30);
          frame2.setLocation(p);
          frame2.show();
          frame2.validate();
          frame2.repaint();
        }

        public SEditorPane()
        {
          super ("text/html", "this is a <a href=link>link</a>");
        }

      }



      The code creates a JEditorPane with a simple HTML string inside a
      JFrame. The JFrame is saved, restored, and redisplayed when the button
      in the control frame is clicked.

      During the save phase, I get this exception:
      java.io.NotSerializableException: javax.swing.text.html.HTML$Tag

      This happens for various text strings I try in the JEditorPane. For
      an empty string, I get a NullPointerException. If I use "text/plain"
      as the content type, the JEditorPane saves and restores fine, but only
      if it is set to "text/plain" for its entire existence. (I.e., you
      can't set the content type in a writeObject() just before you save it;
      the NotSerializableException is still thrown.)

      Past bug reports I found in a search seem to indicate that this has
      been fixed for 1.2.x. This appears not to be the case for 1.3.
      (Review ID: 112387)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: