Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-313

'package' accessible methods not handled correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-4
    • 1.0-beta-6
    • None
    • None
    • Windows XP, Sun JDK 1.4.2

    Description

      Calling a 'package' accessible method (in a Java class) from a groovy script in a different package results in a java.lang.IllegalAccessError, but calling a private method is ok. Since setAccessible is used to gain access to all methods, I assume that package private methods should be callable as well.

      Steps to reproduce:
      1) Compile the Java class included at the end
      2) Add it to the classpath
      3) Start the groovy shell and type:
      1> f = new bar.Foo()
      2> f.priv()
      3> f.pack()
      4> go
      4) You should see this:
      -----------------------------------------------------------
      []
      I am private
      >>> a serious error occurred: tried to access method bar.Foo.pack()V from class
      gjdk.bar.Foo_GroovyReflector
      >>> stacktrace:
      java.lang.IllegalAccessError: tried to access method bar.Foo.pack()V from class
      gjdk.bar.Foo_GroovyReflector
      -----------------------------------------------------------

      Notice that it was ok to call the private method, but not ok to call the package accessible method.

      package bar;
      public class Foo
      {
      public void pub()

      { System.out.println("I am public"); }

      protected void prot()

      { System.out.println("I am protected"); }

      void pack()

      { System.out.println("I am package"); }

      private void priv()

      { System.out.println("I am private"); }

      }

      Attachments

        Activity

          People

            spullara Sam Pullara
            staffan Staffan Larsen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: