JDK-4667053 : LTP: XMLEncoder arrayIndexOutOfBoundsException with JTable in JScrollPane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.0,1.4.2
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_98,windows_xp
  • CPU: x86
  • Submitted: 2002-04-12
  • Updated: 2021-07-13
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.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
Name: gm110360			Date: 04/11/2002


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


FULL OPERATING SYSTEM VERSION :
Windows 98 [version 4.10.1998]


A DESCRIPTION OF THE PROBLEM :
Getting an arrayIndexOutOfBoundsException when using
XMLEncoder on the following :

Trying to encode a JDesktopPane which has one JInternalFrame
which has a JPanel which has a JScrollPane holding a JTable.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. run sample code
2. select encode on the menu bar
3.

EXPECTED VERSUS ACTUAL BEHAVIOR :
see description

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ArrayIndexOutOfBoundsException
        at
java.beans.DefaultPersistenceDelegate.initBean(DefaultPersistenceDelegate.java:3
40)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:395)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:103)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeExpression(Encoder.java:260)
        at java.beans.XMLEncoder.writeExpressionException thrown =
java.lang.ArrayIndexOutOfBoundsException
(XMLEncoder.java:351)
        at
java.beans.DefaultPersistenceDelegate.doProperty(DefaultPersistenceDelegate.java
:219)
        at
java.beans.DefaultPersistenceDelegate.initBean(DefaultPersistenceDelegate.java:2
54)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:395)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:103)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeExpression(Encoder.java:260)
        at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:351)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeObject1(Encoder.java:192)
        at java.beans.Encoder.cloneStatement(Encoder.java:205)
        at java.beans.Encoder.writeStatement(Encoder.java:236)
        at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:320)
        at
java.beans.DefaultPersistenceDelegate.invokeStatement(DefaultPersistenceDelegate
.java:242)
        at
java.beans.java_awt_Container_PersistenceDelegate.initialize(MetaData.java:378)
        at
java.beans.PersistenceDelegate.initialize(PersistenceDelegate.java:191)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:393)
        at
java.beans.javax_swing_JComponent_PersistenceDelegate.initialize(MetaData.java:5
65)
        at
java.beans.PersistenceDelegate.initialize(PersistenceDelegate.java:191)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:393)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:103)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeExpression(Encoder.java:260)
        at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:351)
        at
java.beans.DefaultPersistenceDelegate.doProperty(DefaultPersistenceDelegate.java
:219)
        at
java.beans.DefaultPersistenceDelegate.initBean(DefaultPersistenceDelegate.java:2
54)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:395)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:103)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeExpression(Encoder.java:260)
        at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:351)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeObject1(Encoder.java:192)
        at java.beans.Encoder.cloneStatement(Encoder.java:205)
        at java.beans.Encoder.writeStatement(Encoder.java:236)
        at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:320)
        at
java.beans.DefaultPersistenceDelegate.invokeStatement(DefaultPersistenceDelegate
.java:242)
        at
java.beans.java_awt_Container_PersistenceDelegate.initialize(MetaData.java:378)
        at
java.beans.PersistenceDelegate.initialize(PersistenceDelegate.java:191)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:393)
        at
java.beans.javax_swing_JComponent_PersistenceDelegate.initialize(MetaData.java:5
65)
        at
java.beans.PersistenceDelegate.initialize(PersistenceDelegate.java:191)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:393)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:103)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeExpression(Encoder.java:260)
        at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:351)
        at
java.beans.DefaultPersistenceDelegate.doProperty(DefaultPersistenceDelegate.java
:219)
        at
java.beans.DefaultPersistenceDelegate.initBean(DefaultPersistenceDelegate.java:2
54)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:395)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:103)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeExpression(Encoder.java:260)
        at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:351)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeObject1(Encoder.java:192)
        at java.beans.Encoder.cloneStatement(Encoder.java:205)
        at java.beans.Encoder.writeStatement(Encoder.java:236)
        at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:320)
        at
java.beans.DefaultPersistenceDelegate.invokeStatement(DefaultPersistenceDelegate
.java:242)
        at
java.beans.java_awt_Container_PersistenceDelegate.initialize(MetaData.java:378)
        at
java.beans.PersistenceDelegate.initialize(PersistenceDelegate.java:191)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:393)
        at
java.beans.javax_swing_JComponent_PersistenceDelegate.initialize(MetaData.java:5
65)
        at
java.beans.PersistenceDelegate.initialize(PersistenceDelegate.java:191)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:393)
        at
java.beans.PersistenceDelegate.initialize(PersistenceDelegate.java:191)
        at
java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java
:393)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:103)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeExpression(Encoder.java:260)
        at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:351)
        at
java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
        at java.beans.Encoder.writeObject(Encoder.java:55)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
        at java.beans.Encoder.writeObject1(Encoder.java:192)
        at java.beans.Encoder.cloneStatement(Encoder.java:205)
        at java.beans.Encoder.writeStatement(Encoder.java:236)
        at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:320)
        at java.beans.XMLEncoder.writeObject(XMLEncoder.java:253)
        at testxmlencoder.TestXMLEncoder.encodeDesktop(TestXMLEncoder.java:113)
        at
testxmlencoder.TestXMLEncoder$1.actionPerformed(TestXMLEncoder.java:82)
        at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1767)
        at
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.ja
va:1820)
        at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
        at
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
        at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
        at
javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1092)
        at
javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenu
ItemUI.java:932)
        at java.awt.Component.processMouseEvent(Component.java:5021)
        at java.awt.Component.processEvent(Component.java:4818)
        at java.awt.Container.processEvent(Container.java:1380)
        at java.awt.Component.dispatchEventImpl(Component.java:3526)
        at java.awt.Container.dispatchEventImpl(Container.java:1437)
        at java.awt.Component.dispatchEvent(Component.java:3367)
        at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2929)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)
        at java.awt.Container.dispatchEventImpl(Container.java:1423)
        at java.awt.Window.dispatchEventImpl(Window.java:1566)
        at java.awt.Component.dispatchEvent(Component.java:3367)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
        at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:1
90)
        at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144
)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)

This bug can be reproduced always.

---------- BEGIN SOURCE ----------

package testxmlencoder;


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.beans.*;
import javax.swing.*;


public class TestXMLEncoder implements ExceptionListener {
    JFrame frame;
    JDesktopPane desktop;
    JPanel panel;
    
    public TestXMLEncoder() {
        
        frame = new JFrame("JFrame");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        panel = new JPanel();
        panel.setLayout(new BorderLayout());
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(createXMLMenu());
        
        JTable table = new JTable(50, 50);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setCellSelectionEnabled(true);
        table.setRowSelectionInterval(0,0);
        table.setColumnSelectionInterval(0,0);
        
        JScrollPane scrollPane = new JScrollPane(table);

        JInternalFrame internalFrame = new JInternalFrame("internal frame",
true, true, true, true);
        internalFrame.getContentPane().add(scrollPane);
        internalFrame.setSize( 400, 200);
        internalFrame.setVisible(true);

        desktop = new JDesktopPane();
        desktop.add(internalFrame);

        panel.add(menuBar, BorderLayout.NORTH);
        
        panel.add(desktop, BorderLayout.CENTER);

        frame.getContentPane().add(panel);

        frame.setBounds(10, 10, 600, 304);
        frame.setVisible(true);

    } // constructor
    

    public static void main(String[] args) {
            
        new TestXMLEncoder();
    }
    

    public void exceptionThrown(Exception excp) {
        System.out.println("Exception thrown = " + excp);
        excp.printStackTrace();
    }
   
        
    protected JMenu createXMLMenu() {
        JMenu menu;
        JMenuItem item;
        AbstractAction    encodeAction;
        AbstractAction    decodeAction;

        menu = new JMenu("File");

        encodeAction = new AbstractAction("Encode") {
            public void actionPerformed(ActionEvent e) {
                try {
                    encodeDesktop();
                } catch (FileNotFoundException excp) {
                    System.out.println("encode file not found");
                };
            } // actionPerformed
        }; // fileEncodeAction AbstractAction

        
        decodeAction = new AbstractAction("Decode") {
            public void actionPerformed(ActionEvent e) {
                try {
                    decodeDesktop();
                } catch (FileNotFoundException excp) {
                    System.out.println("decode file not found");
                };
            } // actionPerformed
        }; // fileDecodeAction AbstractAction

        menu.add(encodeAction);
        menu.add(decodeAction);
                
        return menu;
    } // createFileMenu
    
    
    public void encodeDesktop() throws FileNotFoundException {
        XMLEncoder e = new XMLEncoder(
                               new BufferedOutputStream(
                                   new FileOutputStream("Test.xml")));
        e.setExceptionListener(this);

        e.writeObject(desktop);

        e.close();

        panel.remove(desktop);
        panel.revalidate();
        panel.repaint();
        desktop = null;
    }
    
    
    public void decodeDesktop() throws FileNotFoundException {
        XMLDecoder d = new XMLDecoder(
                          new BufferedInputStream(
                              new FileInputStream("Test.xml")));
        Object result = d.readObject();
        d.close();

        desktop = (JDesktopPane)result;
        
        JInternalFrame frames[] = desktop.getAllFrames();

        for (int i = 0; i < frames.length; i++) {
            frames[i].setVisible(true);
            frames[i].setSize( 400, 200);
        }

        panel.add(desktop, BorderLayout.CENTER);
        panel.revalidate();
        panel.repaint();
    }

    
} // class TestXMLEncoder
---------- END SOURCE ----------
(Review ID: 145029) 
======================================================================

Comments
EVALUATION We should create persistence delegate for the following class: javax.swing.plaf.basic.BasicTableHeaderUI$MouseInputHandler
30-10-2006

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon
14-06-2004

EVALUATION There may be a lingering problem with persiting JScrollPanes. It seems to rely on a very hacky ContainerPersistenceDelegate. ###@###.### 2002-04-19 The JDC comment suggests to change like 340 to reference the newL instead of the oldL array. This did not solve the exception. However, I will commit to solve this for 1.5. ###@###.### 2003-07-07 An interim solution in which bounds checking is implemented in the DefaultPersistenceDelegate and a custom persistence delegate for the JScrollPane is introduced. This will encode. If the mouse enters the JTable then it won't encode. This could be a separate bug. ###@###.### 2003-09-19 This problem appears to be a result of the mouse/menu listener attached to the JInternalFrame when the mouse hovers over it. I re-wrote the test case to use a panel with buttons to encode/decode the desktop and if I didn't use the mouse to enter the internal frame then the exception would not occur. It appears that a mouse listener/handler has been added to the internal frame or scrollpane which is pulling a lot of stuff to be archived. This will not make the cut for tiger since tables in scrollpanes are archivable. ###@###.### 2003-10-17
17-10-2003

SUGGESTED FIX *** /tmp/geta17131 2003-09-19 15:04:22.000000000 -0700 --- MetaData.java 2003-09-19 14:52:28.000000000 -0700 *************** *** 542,547 **** --- 542,556 ---- } } + class javax_swing_JScrollPane_PersistenceDelegate extends DefaultPersistenceDelegate { + protected Expression instantiate(Object oldInstance, Encoder out) { + javax.swing.JScrollPane s = (javax.swing.JScrollPane)oldInstance; + return new Expression(oldInstance, s.getClass(), + "new", new Object[]{ s.getViewport().getView() }); + } + } + + *** /tmp/geta17151 2003-09-19 15:04:43.000000000 -0700 --- DefaultPersistenceDelegate.java 2003-09-19 14:50:02.000000000 -0700 *************** *** 333,339 **** String removeListenerMethodName = d.getRemoveListenerMethod().getName(); for (int i = oldL.length; i < newL.length; i++) { ! invokeStatement(oldInstance, removeListenerMethodName, new Object[]{oldL[i]}, out); } } } --- 333,339 ---- String removeListenerMethodName = d.getRemoveListenerMethod().getName(); for (int i = oldL.length; i < newL.length; i++) { ! invokeStatement(oldInstance, removeListenerMethodName, new Object[]{newL[i]}, out); } } } ###@###.### 2003-09-19
19-09-2003