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

Serialization example in java.awt.Component is flawed

    XMLWordPrintable

Details

    • b95
    • x86
    • windows_xp

    Description

      A DESCRIPTION OF THE PROBLEM :
      In the "Serialization" section of the documentation, two code examples are given. The first is deliberately flawed code. The second is intended to fix the problem in the first example, but it actually does not (a non-static inner class was used in example two where a *static* inner class should have been used).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
          import java.awt.*;
          import java.awt.event.*;
          import java.io.Serializable;

          class MyApp java.io.Serializable
          {
               BigObjectThatShouldNotBeSerializedWithAButton bigOne;
               Button aButton = new Button();

               // Note that this inner class is declared "static"
               static class MyActionListener implements ActionListener
               {
                   public void actionPerformed(ActionEvent e)
                   {
                       System.out.println("Hello There");
                   }
               }
       
               MyApp()
               {
                   aButton.addActionListener(new MyActionListener());
               }
          }
      ACTUAL -
          import java.awt.*;
          import java.awt.event.*;
          import java.io.Serializable;

          class MyApp java.io.Serializable
          {
               BigObjectThatShouldNotBeSerializedWithAButton bigOne;
               Button aButton = new Button();

               class MyActionListener implements ActionListener
               {
                   public void actionPerformed(ActionEvent e)
                   {
                       System.out.println("Hello There");
                   }
               }
       
               MyApp()
               {
                   aButton.addActionListener(new MyActionListener());
               }
          }

      URL OF FAULTY DOCUMENTATION :
      http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html
      ###@###.### 2005-04-11 08:48:42 GMT

      Attachments

        Activity

          People

            son Oleg Sukhodolsky (Inactive)
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: