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

Runtime IllegalAccessError when accessing protected method of the owning class's superclass from a closure when using @CompileStatic

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.3.6, 2.4.0-beta-3
    • Fix Version/s: 2.3.7
    • Component/s: Static compilation
    • Labels:
      None

      Description

      Consider the following base class:

      package l
      class Base {
      	protected foo() {
      		println 'foo'
      	}
      }
      

      and the following extended class (please note it's in a different package!):

      package m
      import groovy.transform.CompileStatic;
      import l.Base;
      @CompileStatic
      class Ext extends Base {
      
      	static main(args) {
      		Ext e = new Ext()
      		e.doSomething()
      	}
      
      	void doSomething() {
      		def c = {
      			foo()
      		}
      		c.call()
      	}
      }
      

      When you run this script, you get:

      Caught: java.lang.IllegalAccessError: tried to access method l.Base.foo()Ljava/lang/Object; from class m.Ext$_doSomething_closure1
      java.lang.IllegalAccessError: tried to access method l.Base.foo()Ljava/lang/Object; from class m.Ext$_doSomething_closure1
      	at m.Ext$_doSomething_closure1.doCall(Ext.groovy:16)
      	at m.Ext$_doSomething_closure1.call(Ext.groovy)
      	at m.Ext.doSomething(Ext.groovy:18)
      	at m.Ext.main(Ext.groovy:11)
      

      If you remove the @CompileStatic from Ext, it works.

      It's quite an annoying problem, because you realize about it only when you go live...
      Maybe the source of the problem is similar to that of GROOVY-6468.

        Attachments

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              mauromol Mauro Molinari
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: