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

Introspection code may fail depending on method ordering.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.1.6, 1.1.7, 1.2.0
    • Fix Version/s: 1.3.0
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      generic, unknown, x86
    • OS:
      generic, solaris_2.5, windows_95

      Description



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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: