Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6570354

DefaultPersistenceDelegate throws an ArrayIndexOutOfBoundsException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 6
    • client-libs
    • b20
    • x86
    • windows_xp
    • Not verified

      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 ----------------

            malenkov Sergey Malenkov (Inactive)
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: