United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4699828 : Browser Crashes when JList used Table's CellEditor&Renderer

Details
Type:
Bug
Submit Date:
2002-06-10
Status:
Resolved
Updated Date:
2003-04-12
Project Name:
JDK
Resolved Date:
2002-08-12
Component:
client-libs
OS:
solaris_8
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
1.4.2 (mantis)

Related Reports
Backport:

Sub Tasks

Description

Name: gm110360			Date: 06/10/2002


FULL PRODUCT VERSION :
java version "1.4.0_00"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_00-b05)
Java HotSpot(TM) Client VM (build 1.4.0_00-b05, mixed mode)


FULL OPERATING SYSTEM VERSION :
SunOS unknown 5.8 Generic_108528-06 sun4u sparc
SUNW,Sun-Blade-10

A DESCRIPTION OF THE PROBLEM :
Netscape 6 w/ Java Plugin 1.3.1 and Netscape 6.2.2 w/ Java
Plugin 1.4 crash when JList is used as CellEditor &
CellRenderer in a JTable. This seems to occur only on
Solaris but was successfully reproduced on multiple machines
and Sun Solaris flavors.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Copy code below and compile.

2. Run in Netscape 6+ (as an applet), a simple table will be
displayed. Select the item in the JList (CRASH BABY).

3. Now try to refresh the browser (Look at it go!)

EXPECTED VERSUS ACTUAL BEHAVIOR :
Obviously, a browser crash is unexpected at this phase.



ERROR MESSAGES/STACK TRACES THAT OCCUR :
===== plugin.trace =====
java.lang.NullPointerException
	at javax.swing.JComponent.deregisterNextFocusableComponent(JComponent.java:992)
	at javax.swing.JComponent.removeNotify(JComponent.java:4293)
	at java.awt.Container.removeNotify(Container.java:2023)
	at javax.swing.JComponent.removeNotify(JComponent.java:4286)
	at javax.swing.JTable.removeNotify(JTable.java:477)
	at java.awt.Container.removeNotify(Container.java:2023)
	at javax.swing.JComponent.removeNotify(JComponent.java:4286)
	at java.awt.Container.removeNotify(Container.java:2023)
	at javax.swing.JComponent.removeNotify(JComponent.java:4286)
	at java.awt.Container.removeNotify(Container.java:2023)
	at javax.swing.JComponent.removeNotify(JComponent.java:4286)
	at javax.swing.JRootPane.removeNotify(JRootPane.java:673)
	at java.awt.Container.removeNotify(Container.java:2023)
	at java.awt.Container.removeNotify(Container.java:2023)
	at sun.plugin.viewer.MNetscapePluginObject.setWindow(MNetscapePluginObject.java:260)
	at sun.plugin.navig.motif.Plugin.doit(Plugin.java:263)
	at sun.plugin.navig.motif.Plugin.start(Plugin.java:96)

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
===== TestApplet.java =====
package com.e4e.uitools.calendar;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class TestApplet extends JApplet {
public void init() {
    JTable table = new JTable();
    table.setDefaultRenderer(Object.class, new ListRenderer());
    table.setDefaultEditor(Object.class, new ListRenderer());
    table.setModel(new DefaultTableModel(3,3));
    this.getContentPane().add(table);
}
}

===== ListRenderer.java =====package com.e4e.uitools.calendar;

import java.awt.Component;
import java.util.EventObject;

import javax.swing.*;
import javax.swing.event.CellEditorListener;
import javax.swing.table.*;

public class ListRenderer extends JList implements TableCellEditor,
TableCellRenderer {

    /**
     * Constructor for ListRenderer.
     */
    public ListRenderer() {
        super();
        DefaultListModel model = new DefaultListModel();
        model.addElement("CRASH BABY);
        this.setModel(model);
    }

    public Component getTableCellEditorComponent(
        JTable table,
        Object value,
        boolean isSelected,
        int row,
        int column) {
        return this;
    }

    public Component getTableCellRendererComponent(
        JTable table,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        int row,
        int column) {
        return this;
    }

    public void addCellEditorListener(CellEditorListener l) {
    }

    public void cancelCellEditing() {
    }

    public Object getCellEditorValue() {
        return null;
    }

    public boolean isCellEditable(EventObject anEvent) {
        return true;
    }

    public void removeCellEditorListener(CellEditorListener l) {
    }


    public boolean shouldSelectCell(EventObject anEvent) {
        return false;
    }

    public boolean stopCellEditing() {
        return false;
    }


}


---------- END SOURCE ----------
(Review ID: 153408) 
======================================================================

                                    

Comments
SUGGESTED FIX



Name: apR10133			Date: 06/14/2002



------- JComponent.java -------
*** /tmp/sccs.LGaG.W	Fri Jun 14 18:45:23 2002
--- JComponent.java	Fri Jun 14 18:38:46 2002
***************
*** 993,998 ****
--- 993,1001 ----
  
  	Container nearestRoot =
  	    (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
+ 	if (nearestRoot == null) {
+ 	    return;
+ 	}
  	FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
  	if (policy instanceof LegacyGlueFocusTraversalPolicy) {
  	    ((LegacyGlueFocusTraversalPolicy)policy).

###@###.###

======================================================================
                                     
2004-08-24
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis
mantis-b02

FIXED IN:
mantis
mantis-b02

INTEGRATED IN:
mantis
mantis-b02
tiger-b03


                                     
2004-08-24
EVALUATION

...

Name: apR10133			Date: 06/14/2002


    This bug can be reproduced with a sufficiently more simple way. It is enough
to create JTable and start the editing of any table's cell. After the "reload"
you will get the same exception.

The cause of this bug is that

ext/plugin/java/src/sun/plugin/viewer/WNetscapePluginObject.java

calls removeAll() on the embedded frame for the plugin and then it calls
removeNotify() on panel for hosting the applet at the setWindow() method.
The JComponent's removeNotify() calls the deregisterNextFocusableComponent()
where we try to get the focus cycle root ancestor and it's focus traversal
policy. But as the applet panel is already removed from the embedded frame
the focus cycle root is null and hence we get the NPE. So we just need to
check if it null.

###@###.###

======================================================================
                                     
2004-08-24



Hardware and Software, Engineered to Work Together