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

java.beans.Statement imposes excessive access control

XMLWordPrintable

    • b46
    • x86
    • windows_xp
    • Verified

      FULL PRODUCT VERSION :
      java version "1.5.0_13"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
      Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)



      ADDITIONAL OS VERSION INFORMATION :
      Windows XP some version ...

      A DESCRIPTION OF THE PROBLEM :
      java.beans.Statement is throwing a NoSuchMethodException when the method exists and is public.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and execute the test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      run


      ACTUAL -
      Exception in thread "main" java.lang.NoSuchMethodException: StatementTestChild.run();
      at java.beans.Statement.invoke(Statement.java:236)
      at java.beans.Statement.execute(Statement.java:123)
      at test.StatementTest.main(StatementTest.java:13)



      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NoSuchMethodException: StatementTestChild.run();
      at java.beans.Statement.invoke(Statement.java:236)
      at java.beans.Statement.execute(Statement.java:123)
      at test.StatementTest.main(StatementTest.java:13)



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

      import java.beans.*;
      import java.lang.reflect.*;

      public class StatementTest
      {
          public static void main(String[] args) throws Exception
          {
              Object[] params = {};
              StatementTestChild p = new StatementTestChild();
              Statement s = new Statement(p, "run", params);
              s.execute();
          }

          public void run()
          {
              System.out.println("run");
          }
      }

      class StatementTestChild extends StatementTest
      {
          public void run()
          {
              System.out.println("run");
          }
      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The test program works if the run() method is inherited from the base class rather than being overridden in the non-public derived class. If the test program was modified to execute the method directly rather than via Statement it compiles and executes.

      The access control being enforced here is beyond what the semantics of Java method execution require, and it isn't specified as being enforced in the Javadoc for java.beans.Statement, which indeed is clear that the JLS rules are supposed to be followed.

            malenkov Sergey Malenkov (Inactive)
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: