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

javax.swing.JTabbedPane cannot be deserialized

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • Resolved In Build:
      b08
    • CPU:
      x86_64
    • OS:
      linux_ubuntu

      Description

      ADDITIONAL SYSTEM INFORMATION :
      I could reproduce the bug on Ubuntu 20.04 with the following JDKs 15, 14, 11 and 9:

      OpenJDK 15-ea build 15-ea+24-1168 , Oracle JDK 14.0.1, OpenJDK 11.0.7, OpenJDK 9 build 9+181

      I could reproduce the bug on Windows 10 build 1909 with the following JDKs 14 and 9:

      Oracle JDK 14.0.1, OpenJDK 9 build 9+181

      However, with JDK 8 everything went fine. I've checked it on Win10 with OpenJDK 1.8.0_41 and on Ubuntu 20.04 with OpenJDK 1.8.0_252.

      A DESCRIPTION OF THE PROBLEM :
      When I want to deserialize a serialized JTabbedPane-object, I get a NullPointerException. I use ObjectInputStream.readObject() for deserializing the JTabbedPane instance.

      REGRESSION : Last worked in version 8u251

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just compile and run the following code in Bee.java:
      javac Bee.java
      java -cp . Bee

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Output of the toString() method of the deserialized JTabbedPane as with JDK 8:

      readPane: javax.swing.JTabbedPane[,0,0,0x0,invalid,layout=javax.swing.plaf.metal.MetalTabbedPaneUI$TabbedPaneLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=352,maximumSize=,minimumSize=,preferredSize=,haveRegistered=false,tabPlacement=TOP]
      ACTUAL -
       ~/Downloads/tmp/openjdk15/jdk-15/bin/javac *.java && ~/Downloads/tmp/openjdk15/jdk-15/bin/java -cp . Bee

      Exception in thread "main" java.lang.NullPointerException
      at java.desktop/javax.swing.JTabbedPane.getTabCount(JTabbedPane.java:1118)
      at java.desktop/javax.swing.plaf.basic.BasicTabbedPaneUI.installTabContainer(BasicTabbedPaneUI.java:308)
      at java.desktop/javax.swing.plaf.basic.BasicTabbedPaneUI.installComponents(BasicTabbedPaneUI.java:304)
      at java.desktop/javax.swing.plaf.basic.BasicTabbedPaneUI.installUI(BasicTabbedPaneUI.java:248)
      at java.desktop/javax.swing.JComponent.setUI(JComponent.java:685)
      at java.desktop/javax.swing.JTabbedPane.setUI(JTabbedPane.java:253)
      at java.desktop/javax.swing.JTabbedPane.updateUI(JTabbedPane.java:269)
      at java.desktop/javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1363)
      at java.desktop/javax.swing.SwingUtilities.updateComponentTreeUI(SwingUtilities.java:1354)
      at java.desktop/javax.swing.JComponent$ReadObjectCallback.validateObject(JComponent.java:5457)
      at java.base/java.io.ObjectInputStream$ValidationList$1.run(ObjectInputStream.java:2758)
      at java.base/java.io.ObjectInputStream$ValidationList$1.run(ObjectInputStream.java:2756)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
      at java.base/java.io.ObjectInputStream$ValidationList.doCallbacks(ObjectInputStream.java:2754)
      at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:506)
      at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:457)
      at Bee.main(Bee.java:31)


      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.io.*;

      public class Bee {

          public static void main(final String[] args) {

              // --------- create tabbed pane
              JTabbedPane tabbedPane = new JTabbedPane();

              // ------------ Test serializing -------------------
              final String file = "swing.ser";
              FileOutputStream fout = null;
              ObjectOutputStream out = null;
              FileInputStream fin = null;
              ObjectInputStream oin = null;

              try {
                  // ______________________ Write tabbedPane... _______________________
                  fout = new FileOutputStream(file);
                  out = new ObjectOutputStream(fout);

                  out.writeObject(tabbedPane);

                  out.close();

                  // ____________________________reading pane___________________
                  fin = new FileInputStream(file);
                  oin = new ObjectInputStream(fin);

                  final JTabbedPane readPane = (JTabbedPane) oin.readObject(); // Das gespeiherte wieder Lese!
                  System.out.println("readPane: " + readPane.toString());
                  oin.close();
                  fin.close();
              } catch (IOException e1) {
                  e1.printStackTrace();
              } catch (ClassNotFoundException e2) {
                  e2.printStackTrace();
              }
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      My current workaround is to use JDK 8 instead of a newer one.

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: