groovy
  1. groovy
  2. GROOVY-4936

package protected method in Parent class cannot be called

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.1, 1.7.11
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      assuming we have

      public class Parent{ 
        int someMethod(){return 1;}
      }

      written in Java and

      public class Child extends Parent{
        int someMethod(){
          return super.someMethod()+2
        }
      }

      written in Groovy, then this results in a StackOverflow.

      1. 4936.patch
        3 kB
        blackdrag blackdrag

        Activity

        Hide
        blackdrag blackdrag added a comment -

        part of the problem is, as described in GROOVY-4922, the logic

        useThis ^ (method.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED)

        But this logic appears twice in MetaClassImpl and a third time in MetaMethod#getMopName

        Show
        blackdrag blackdrag added a comment - part of the problem is, as described in GROOVY-4922 , the logic useThis ^ (method.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED) But this logic appears twice in MetaClassImpl and a third time in MetaMethod#getMopName
        Hide
        blackdrag blackdrag added a comment -

        attaching a partial patch. This fixes the stack overflow problem, but with this patch we still have 1 failing test. Which is funnily the formerly passing test for GROOVY-4922 I added earlier. It fails now with: tried to access method groovy.bugs.Groovy4922BugSupport.someMethod(Ljava/lang/String;)V
        Which means the logic is not yet right like this maybe

        Show
        blackdrag blackdrag added a comment - attaching a partial patch. This fixes the stack overflow problem, but with this patch we still have 1 failing test. Which is funnily the formerly passing test for GROOVY-4922 I added earlier. It fails now with: tried to access method groovy.bugs.Groovy4922BugSupport.someMethod(Ljava/lang/String;)V Which means the logic is not yet right like this maybe
        Hide
        blackdrag blackdrag added a comment - - edited

        The stack is:

        java.lang.IllegalAccessError: tried to access method groovy.bugs.Groovy4922BugSupport.someMethod(Ljava/lang/String;)V from class groovy.bugs.Groovy4922BugChild
        at groovy.bugs.Groovy4922BugChild.super$2$someMethod(TestScripttestShouldNotThrowStackOverflow82.groovy) 
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        Show
        blackdrag blackdrag added a comment - - edited The stack is: java.lang.IllegalAccessError: tried to access method groovy.bugs.Groovy4922BugSupport.someMethod(Ljava/lang/ String ;)V from class groovy.bugs.Groovy4922BugChild at groovy.bugs.Groovy4922BugChild. super $2$someMethod(TestScripttestShouldNotThrowStackOverflow82.groovy) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        Hide
        blackdrag blackdrag added a comment -

        What can be seen here is, correct super$2$someMethod method is selected and executed, but it has no access to the package private parent class method. The question is why. They are in the same package, so there should be no problem with that.

        Show
        blackdrag blackdrag added a comment - What can be seen here is, correct super$2$someMethod method is selected and executed, but it has no access to the package private parent class method. The question is why. They are in the same package, so there should be no problem with that.
        Hide
        blackdrag blackdrag added a comment -

        The reason for the IllegalAccessError is that in the test the class loaders for the Child and for the parent are different. In terms of package private that means that no access is allowed and the IllegalAccessError is correct. Thus I changed the test to use the PackaScope transformation instead and then all tests pass.

        Show
        blackdrag blackdrag added a comment - The reason for the IllegalAccessError is that in the test the class loaders for the Child and for the parent are different. In terms of package private that means that no access is allowed and the IllegalAccessError is correct. Thus I changed the test to use the PackaScope transformation instead and then all tests pass.

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            blackdrag blackdrag
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: