JDK-6687962 : JTable now calls configureEnclosingScrollPane() from its constructor.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp,windows_vista
  • CPU: x86
  • Submitted: 2008-04-14
  • Updated: 2011-02-16
  • Resolved: 2008-06-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6u10 b26Fixed
Related Reports
Duplicate :  
Description
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.

Comments
EVALUATION This is a regression of the fix for 6610132: NimbusLAF: Minor Cosmetic bugs round up for 6u10-b12
14-04-2008