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

java.bean.Introspector does not conform to the specs and is inconsistent

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • None
    • 1.3.0
    • client-libs
    • generic
    • generic

    Description



      Name: boT120536 Date: 01/22/2001


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)

      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)

      Same thing on Solaris j2se1_3_0

      The JDK 1.3.0 version of java.beans.Introspector is broken, and behavior is not
      consistent across JVM version (1.2.2). This is a problem when using java beans
      from a JSP engine that would report not finding properties for a given bean.
      Following is a detailed description of the problems as they were observed during
      our debug phase. Other problems might be lying in the Introspector
      when using the low-level introspection though.

      1) depending on the order of the method declaration it would fail to list some
      available properties, when types are mixed between boolean and simple return
      value:

      If I define:
          public boolean isQueryTranslated()
          {
                  return false;
          }

          public void setQueryTranslated(String s1)
          {
          }

          public String getQueryTranslated()
          {
                  return "";
          }

      Then the JDK 1.3.0 would *not* find the write method of the property
      'queryTranslated'

      However, if I change the order of the method declaration to the following:
          public void setQueryTranslated(String s1)
          {
          }

          public String getQueryTranslated()
          {
                  return "";
          }

          public boolean isQueryTranslated()
          {
                  return false;
          }

      Then the JDK 1.3.0 *would* find the write method of the property
      'queryTranslated'
      In addition, for this example JDK 1.2.2 and JDK 1.3.0 does not behave
      consistently!


      2) under some [undiagnosed] circumstances, it would fail to list all available
      properties

      In the attached ConfigBean example, under the JDK 1.2.2, my assumption reading
      the specs is that I should obtain 4 properties:
      'queryTranslatable' (boolean read), 'loginPassword' (string read), 'loginName'
      (string read) and 'queryTranslated' (string Read Write)
       I would obtain a list of 4 properties, whereas the JDK 1.3.0 would only find
      two: 'loginPassword' and 'queryTranslated'
      It seems to me that there is a logic bug in the java Beans introspection, where
      not only the presence of a property in methods is checked for instead of full
      pattern matching (ie using string.indexOf() >0 instead of String.equals())


      For reference, here is what the specs version 1.0.1 say:
      "8.3.1 Simple properties
      By default, we use design patterns to locate properties by looking for methods
      of the form:
      public < PropertyType> get< PropertyName>();
      public void set< PropertyName>(< PropertyType> a);
      If we discover a matching pair of "get<PropertyName>" and "set<PropertyName>"
      methods
      that take and return the same type, then we regard these methods as defining a
      read-write prop-erty
      whose name will be "<propertyName>". We will use the "get<PropertyName>" method
      to get the property value and the "set<PropertyName>" method to set the property
      value. The
      pair of methods may be located either in the same class or one may be in a base
      class and the
      other may be in a derived class.
      If we find only one of these methods, then we regard it as defining either a
      read-only or a write-only
      property called "<propertyName>"
      By default we assume that properties are neither bound nor constrained (see
      Section 7).
      So a simple read-write property "foo" might be represented by a pair of methods:
      public Wombat getFoo();
      public void setFoo(Wombat w);

      8.3.2 Boolean properties
      In addition, for boolean properties, we allow a getter method to match the
      pattern:
      public boolean is< PropertyName>();
      This "is<PropertyName>" method may be provided instead of a "get<PropertyName>"
      meth-od,
      or it may be provided in addition to a "get<PropertyName>" method.
      In either case, if the "is<PropertyName>" method is present for a boolean
      property then we will
      use the "is<PropertyName>" method to read the property value.
      An example boolean property might be:
      public boolean isMarsupial();
      public void setMarsupial(boolean m);
      "





      Here is the test driver that I used for performing by tests:


      package custom.client.jsp;

      import custom.client.jsp.ConfigBean;

      public class TestObfuscation {
          public TestObfuscation (){

          }

          public static void main (String[] args) {
      try {

      Class myClass = ConfigBean.class;
      String prop = "queryTranslated";

      java.beans.BeanInfo info
      = java.beans.Introspector.getBeanInfo(myClass);
      if ( info != null ) {
      java.beans.PropertyDescriptor pd[]
      = info.getPropertyDescriptors();
      for (int i = 0 ; i < pd.length ; i++) {
      System.out.println("\n\ni=" + i + "\n");
      System.out.println("pd[i]:" + pd[i]);
      System.out.println("pd[i].getReadMethod():" +
      pd[i].getReadMethod());
      System.out.println("pd[i].getName(): [" + pd[i].getName() + "]");
      System.out.println("pd[i].getName().equals(prop) :" +
      pd[i].getName().equals(prop));
      System.out.println("pd[i].getWriteMethod():" +
      pd[i].getWriteMethod());

      if ( pd[i].getName().equals(prop) ) {
      System.out.println("method:" + pd[i].getWriteMethod());
      System.out.println("type:" + pd[i].getPropertyType());
      break;
      }
      }
      }
      } catch(Exception e) {
      e.printStackTrace();
      }
          } // end of main ()
          
      }// TestObfuscation


      Here is the simplified version of the ConfigBean class that is the introspected
      bean:

      package custom.client.jsp;

      import java.util.Enumeration;
      import java.util.Vector;


      public class ConfigBean
      {

          private String a;
          private String b;
          private boolean g;
          private boolean h;
          private String m;
          private Enumeration p;

          private Enumeration c;
          private Enumeration f;
          private Enumeration e;
          private Enumeration k;
          private Enumeration i;
          private String d[];
          private String q[];
          private String l[];


          public boolean isQueryTranslatable()
          {
                  return false;
          }


          public String getLoginPassword()
          {
                  return "";
          }

          public String getLoginName()
          {
                  return "";
          }


      // public boolean isQueryTranslated()
      // {
      // return false;
      // }

          public void setQueryTranslated(String s1)
          {
          }

          public String getQueryTranslated()
          {
                  return "";
          }


      // public String getQueryLanguage()
      // {
      // return "";
      // }

      // public void setQueryLanguage(String s1)
      // {
      // }


      }
      (Review ID: 115521)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              mdavidsosunw Mark Davidson (Inactive)
              bonealsunw Bret O'neal (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: