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

JTable now calls configureEnclosingScrollPane() from its constructor.

XMLWordPrintable

    • b26
    • x86
    • windows_xp, windows_vista

      FULL PRODUCT VERSION :
      java version "1.6.0_10-beta"
      Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b21)
      Java HotSpot(TM) Client VM (build 11.0-b11, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Window XP, Windows Vista

      A DESCRIPTION OF THE PROBLEM :
      In JRE Update 10 JTable has changed so that it calls configureEnclosingScrollPane() from updateUI(), which is called from its constructor. This causes the sequence of events below:

      Pre Update 10:
      Parent.constructor() -> creates JTable subclass -> Parent.constructor() completes -> JTable subclass.configureEnclosingScrollPane() called later.

      Update 10:
      Parent.constructor() -> creates JTable subclass -> JTable subclass.configureEnclosingScrollPane() called -> parent members are NULL because they are not set until after constructor has finished.

      An existing applet of ours uses a member class to override JTable.configureEnclosingScrollPane() and read a member field in the parent class. In previous version JREs this worked, but in Update 10 the call to configureEnclosingScrollPane() from JTable's constructor means that the parent's members are not initialized yet, so when we try to read them they are null, as the stack trace below shows:

      java.lang.NullPointerException
      at com.altio.examples.applets.JTableTest$SimpleTable.configureEnclosingScrollPane(JTableTest.java:42)
      at javax.swing.JTable.updateUI(Unknown Source)
      at javax.swing.JTable.<init>(Unknown Source)
      at javax.swing.JTable.<init>(Unknown Source)

      Now we can obviously work around this issue by changing our code, and we have done so, but the problem is that we have versions of our applet deployed to customers that will not contain this fix, and so if they update to Java 6 Update 10 their application will stop working.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use an inner class to subclass JTable, override JTable.configureEnclosingScrollPane() and try to read the value of a member variable of your parent class.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The value of the member variable should be available from configureEnclosingScrollPane().
      ACTUAL -
      A NullPointerException is thrown when attempting to use member objects, as configureEnclosingScrollPane() is called from updateUI() which is now called from JTable's constructor, and so members are not yet initialized.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.NullPointerException
      at com.altio.examples.applets.JTableTest$SimpleTable.configureEnclosingScrollPane(JTableTest.java:42)
      at javax.swing.JTable.updateUI(Unknown Source)
      at javax.swing.JTable.<init>(Unknown Source)
      at javax.swing.JTable.<init>(Unknown Source)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package com.altio.examples.applets;

      import java.awt.FlowLayout;

      import javax.swing.JApplet;
      import javax.swing.JTable;
      import javax.swing.SwingUtilities;

      public class JTableTest extends JApplet {
        
        protected String testValue;
        private SimpleTable _table = null;
        
        public JTableTest() {
          _table = new SimpleTable();
          testValue = "Something";
        }
        
        public void start() {
          super.start();
          Runnable r = new Runnable() {
            public void run() {
              addGUI();
            }
          };
          SwingUtilities.invokeLater(r);
        }

        private void addGUI() {
          getContentPane().setLayout(new FlowLayout());
          this.getContentPane().add(_table);
        }
        
        class SimpleTable extends JTable {
          public SimpleTable() {
            super();
            System.out.println("SimpleTable instantiated");
          }
          
          protected void configureEnclosingScrollPane() {
            try {
              final int test = testValue.length();
            }
            catch (NullPointerException npe) {
              npe.printStackTrace();
            }
            super.configureEnclosingScrollPane();
          }
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Check for null objects before attempting to use them. Impact is not on future development but upon existing clients using our software who upgrade their JRE.

      Release Regression From : 6u10
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

            jasper Jasper Potts (Inactive)
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: