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

DOC: LTP: Unspecified NPE in java.beans.DefaultPersistenceDelegate.instantiate method

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 7
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
    • Introduced In Build:
      b76
    • Introduced In Version:
      6
    • Resolved In Build:
      b84
    • CPU:
      generic
    • OS:
      generic

      Description

      The problem is that if to run java.beans.DefaultPersistenceDelegate.instantiate(Object oldInstance, Encoder out) method with parameter "out = null" then unspecified NPE happens is some cases (*since b76*).

      Steps to reproduce:
      1)if java bean is located in separate MyBean.java file in the same package, but it is not public
      ------------------File Bean.java -------------------------------------------
      import java.beans.*;

      public class Bean{

      public static void main(String args[]){

               Object oldInstance = new MyBean("Test");
               String[] constructorPropertyNames = {"arg"};
      MyPersistenceDelegate dpd = new MyPersistenceDelegate(constructorPropertyNames);

               Expression exp = dpd.instantiate(oldInstance, null);
                            //Expression exp = dpd.instantiate(oldInstance, new Encoder());

      System.out.println(exp);
      }
      }

      class MyPersistenceDelegate extends DefaultPersistenceDelegate {

          public MyPersistenceDelegate() {
              super();
          }

          public MyPersistenceDelegate(String[] constructorPropertyNames) {
              super(constructorPropertyNames);
          }

          public Expression instantiate(Object oldInctance, Encoder out) {
              return super.instantiate(oldInctance, out);
          }
      }

      ------------------File MyBean.java -------------------------------------------
      class MyBean {
          private String arg;
          public MyBean() {
              super();
          }
          public MyBean(String arg) {
              this.arg = arg;
          }
          public String getArg() {
              return arg;
          }
          public void setArg(String arg) {
              this.arg = arg;
          }
      }
      ======================================================================================================================================
      2) if java bean is located in the same Bean.java file. (See example in CR 6401499)

      In case if "out = new Encoder();" (!= null) and MyBean class *is not public* then another problem arise:
      If uncomment the commented line in example 1) then you'll see the following output:
      --------------
      java.lang.IllegalAccessException: Class java.beans.DefaultPersistenceDelegate can not access a member of class bugfixbeans.test.MyBean with modifiers "public"
      Continuing ...
      MyBean=Class.new(null);
      --------------

      Which is not expected.
      Expected output is:
      ---------------
      MyBean=Class.new("Test");
      --------------

      It seems to be that such behaviour should be either corrected or specified.

      See also CR 6401499.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              malenkov Sergey Malenkov (Inactive)
              Reporter:
              ynovozhi Yulia Novozhilova (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: