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

Introspector creates indexed property descriptor from non-indexed property

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.1.6
    • client-libs
    • x86
    • windows_nt

    Description



      Name: chT40241 Date: 08/25/98


      /**
       * This sample program demonstrates a bug in the
       * java.beans.Introspector.
       * The bug is that the Introspector creates an indexed property
       * from the IntrospectorTestSubClass below. The get/set
       * methods for the property are those of a non-indexed
       * property. The Introspector should create either a
       * non-indexed property or create both an indexed and
       * non-indexed property.
       *
       * This can be worked around by providing additional BeanInfo
       * for the class.
       * However, that is cumbersome for a large class library.
       *
       * Output from program:
       * <PRE>
       * Descriptor: java.beans.IndexedPropertyDescriptor@1ec96f
       * Read method: public java.lang.Object
       * com.sastest.beans.IntrospectorTestSubClass.getFoo()
       * Write method: public void
       * com.sastest.beans.IntrospectorTestSubClass.setFoo
       * (java.lang.Object)
       * </PRE>
      */
      package com.sastest.beans;

      import java.beans.BeanInfo;
      import java.beans.Introspector;
      import java.beans.PropertyDescriptor;

      public class IntrospectorTest {
         public static void main( String[] args ) {
            try {
               BeanInfo beanInfo =
                         Introspector.getBeanInfo(
                                      IntrospectorTestSubClass.class );
               PropertyDescriptor[] descriptors =
                                     beanInfo.getPropertyDescriptors();
               for ( int i = 0; i < descriptors.length; i++ ) {
                  if ( descriptors[i].getName().equals( "foo" ) ) {
                     System.out.println( "Descriptor: " +
                                          descriptors[i] );
                     System.out.println( "Read method: " +
                                      descriptors[i].getReadMethod() );
                     System.out.println( "Write method: " +
                                     descriptors[i].getWriteMethod() );
                     } // if
                } // for
            }
            catch (Exception e) {
               System.out.println( "Exception: " + e );
            }
         }
      }

      /**
       * This class approximates java.awt.TextField with the "foo"
       * property standing in for "preferredSize".
       */
      class IntrospectorTestBaseClass {
         private Object foo;
         public Object getFoo() {
            return foo;
         }
         public Object getFoo( int bar ) {
            return new Integer(bar);
         }
      }

      /**
       * This class approximates our subclass of java.awt.TextField
       * with the "foo" property standing in for "preferredSize".
       */
      class IntrospectorTestSubClass extends IntrospectorTestBaseClass {
         private Object foo;
         public void setFoo( Object foo ) {
            this.foo = foo;
         }
      }

      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              mdavidsosunw Mark Davidson (Inactive)
              chickeysunw Chuck Hickey (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: