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

Introspection code may fail depending on method ordering.

XMLWordPrintable

    • beta
    • generic, unknown, x86
    • generic, solaris_2.5, windows_95



      Name: tb29552 Date: 06/01/98


      DESCRIPTION
      =============

      java.beans has a bug in PropertyDescriptor when
      it tries to check for read&write (setter&getter) methods for a property.
      If the class provides 2 setters for the same property, for
      convenience, the code in java.beans may fail depending
      on which method is declared first in the class.

      This type of code is present even in SUN's BDK example.
      For instance, BridgeTester has 2 methods "setByteValue" , one
      where a byte is passed, and another one where an int is passed.
      Because of the order in which these methods were defined the bug
      does not appear.


      STEPS TO RECREATE
      ====================

      Try to compile & run the 2 classes included below.
      One will cause the exception, the other won't. The exception will be like this

      C:\beans>java beans.SunsBug1
      java.beans.IntrospectionException: type mismatch between read and write methods
              at java.beans.PropertyDescriptor.findPropertyType(PropertyDescriptor.java:252)
              at java.beans.PropertyDescriptor.<init>(PropertyDescriptor.java:63)
              at beans.SunsBug1.main(SunsBug1.java:25)


      // -- = - = - CLASS SunsBug1 - = - = - = - =

      package beans;

      /**
       * This type was generated by a SmartGuide.
       */
      public class SunsBug1 {
      private int foo = 0;

      public SunsBug1 ( ) {
      }
      public int getFooValue () {
      return foo;
      }
      public static void main(java.lang.String[] args) {
      Object bean = null;
      try {
      bean = java.beans.Beans.instantiate (null, "beans.SunsBug1");

      java.beans.BeanInfo bi = java.beans.Introspector.getBeanInfo (bean.getClass());

      java.beans.PropertyDescriptor pd = new java.beans.PropertyDescriptor("fooValue", bean.getClass());
      } catch (Exception e) {e.printStackTrace();}

      }
      public void setFooValue (byte newValue ) {
      foo = newValue;
      }
      public void setFooValue (int newValue ) {
      foo = newValue;
      }
      }

      // - = - = - = CLASS SunsBug2- = - = - = - = - =


      package beans;

      /**
       * This type was generated by a SmartGuide.
       */
      public class SunsBug2 {
      private byte bar = 0;

      public SunsBug2 ( ) {
      }
      public byte getBarValue () {
      return bar;
      }
      public static void main(java.lang.String[] args) {
      Object bean = null;
      try {
      bean = java.beans.Beans.instantiate (null, "beans.SunsBug2");

      java.beans.BeanInfo bi = java.beans.Introspector.getBeanInfo (bean.getClass());

      java.beans.PropertyDescriptor pd = new java.beans.PropertyDescriptor("barValue", bean.getClass());
      } catch (Exception e) {e.printStackTrace();}

      }
      public void setBarValue (byte newValue ) {
      bar = newValue;
      }
      public void setBarValue (int newValue ) {
      bar = (byte) newValue;
      }
      }
      (Review ID: 24072)
      ======================================================================

            jkoenigsunw Janet Koenig (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: