groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mauro Molinari (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8441) IllegalAccessError when calling a public method on a field whose type is declared to be a package-private implementation one
Date Wed, 10 Jan 2018 13:37:00 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-8441?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Mauro Molinari updated GROOVY-8441:
-----------------------------------
    Summary: IllegalAccessError when calling a public method on a field whose type is declared
to be a package-private implementation one  (was: IllegalAccessError when calling a public
method on a package-private implementation instance)

> IllegalAccessError when calling a public method on a field whose type is declared to
be a package-private implementation one
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-8441
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8441
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.13
>            Reporter: Mauro Molinari
>
> This seems somewhat similar to GROOVY-7549.
> Consider the following interface:
> {code:java}
> package test18;
> public interface Iface {
> 	String getBar();
> }
> {code}
> and a package-private implementation:
> {code:java}
> package test18;
> class IfaceImpl implements Iface {
> 	@Override
> 	public String getBar() {
> 		return "bar";
> 	}
> }
> {code}
> Now the following base class:
> {code:java}
> package test18;
> public class Base {
> 	private IfaceImpl foo = new IfaceImpl(); 
> 	
> 	public Iface getFoo() {
> 		return foo;
> 	}
> }
> {code}
> Please note: the field is declared with the implementation type, the getter is public,
but the getter declared return type is the public interface.
> Then this Groovy class:
> {code:groovy}
> package test18.sub
> import groovy.transform.CompileDynamic
> import groovy.transform.CompileStatic
> import test18.Base
> class Test18 extends Base {
> 	
> 	@CompileStatic
> 	void foobar() {
> 		println foo.bar
> 	}
> 	
> 	static main(args) {
> 		Test18 t = new Test18()
> 		println t.foo.bar
> 		t.foobar()
> 	}
> }
> {code}
> Please note the package is different.
> If you run this code, the first {{bar}} is written correctly, the second invocation fails
with: {{java.lang.IllegalAccessError: tried to access class test18.IfaceImpl from class test18.sub.Test18}}.
> Workarounds:
> - remove {{@CompileStatic}} from {{Test18.foobar()}} (or declare it with {{@CompileDynamic}}
if the whole class is statically compiled)
> - change the declaration of {{Base.foo}} to be of type {{Iface}} rather than {{IfaceImpl}}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message