Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6570354
Votes 1
Synopsis DefaultPersistenceDelegate throws an ArrayIndexOutOfBoundsException
Category java:classes_beans
Reported Against
Release Fixed 7(b20)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 6243086 , 4667053 , 6582164
Submit Date 15-JUN-2007
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
at last of  method initBean(Class type, Object oldInstance, Object newInstance, Encoder out):
line 316:
String removeListenerMethodName = d.getRemoveListenerMethod().getName();
            for (int i = oldL.length; i < newL.length; i++) {
                invokeStatement(oldInstance, removeListenerMethodName, new Object[]{oldL[i]}, out);
// the upper line should be
invokeStatement(oldInstance, removeListenerMethodName, new Object[]{newL[i]}, out);

            }

It is obvious that if the for loop is executed, you are trying to access "oldL" with an illegal index because i >= oldL.length.
I think this may be a clerical error and "newL" should be used inside the for loop.

The exception will be thrown when we remove some default listeners from an instance. In one word, if oldL.length < newL.length,
an ArrayIndexOutOfBoundsException will be thrown.


REPRODUCIBILITY :
This bug can be reproduced occasionally.


-------------  begin ----------------
/*
 * Test.java
 *
 * Created on June 15, 2007, 2:41 PM
 *
 */

import java.awt.BorderLayout;
import java.beans.ExceptionListener;
import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.plaf.basic.BasicLabelUI;

public class Test {
    
    /** Creates a new instance of Test */
    public Test() {
        JPanel panel = new JPanel(new BorderLayout());
        JLabel label = new JLabel("");
        //the following line is ugly and useless
        //but I have to do something to detonate the bomb
        label.removePropertyChangeListener((BasicLabelUI)label.getUI());
        
        panel.add(label);
        
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLEncoder encoder =  new XMLEncoder(out);
        encoder.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                e.printStackTrace();
                System.err.println("Continuing ...");
            }
        });
        encoder.writeObject(panel);
        encoder.flush();
        encoder.close();
        String xml;
        try {
            xml = new String(out.toByteArray(), "UTF-8");
            System.out.println(xml);
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        }

    }
    
    public static void main(String[] args) {
        Test app = new Test();
    }
}
-------------  end ----------------
Posted Date : 2007-06-15 21:46:17.0
Work Around
N/A
Evaluation
This problem was found while some other bugs were investigated.
We should fix this bug before the following bugs: 4667053 & 6243086.
Posted Date : 2007-06-19 10:01:44.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang