United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6687962 JTable now calls configureEnclosingScrollPane() from its constructor.
JDK-6687962 : JTable now calls configureEnclosingScrollPane() from its constructor.

Details
Type:
Bug
Submit Date:
2008-04-14
Status:
Resolved
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2008-06-09
Component:
client-libs
OS:
windows_vista,windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u10
Fixed Versions:
6u10 (b26)

Related Reports
Duplicate:

Sub Tasks

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
                                     
2008-04-14



Hardware and Software, Engineered to Work Together