[
https://issues.apache.org/jira/browse/GROOVY-11365?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17842671#comment-17842671
]
Eric Milles commented on GROOVY-11365:
--------------------------------------
My test script gives an access error with Groovy 3.0.21, 4.0.13, 4.0.14,
4.0.17, 4.0.21, and so on.
There are scenarios (that were fixed) where static compilation stops being
applied for inner types. Not sure if you fell into one of those. But you are
saying the bytecode generated for the doCall of the closure is the same. Are
you able to produce a script (or project) that works for 4.0.14 and fails now.
> IllegalAccessError when using protected method as reference
> -----------------------------------------------------------
>
> Key: GROOVY-11365
> URL: https://issues.apache.org/jira/browse/GROOVY-11365
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 4.0.18, 5.0.0-alpha-8, 4.0.21
> Reporter: Christopher Smith
> Assignee: Eric Milles
> Priority: Critical
>
> I will try to repro this, but posting in case the description is sufficient
> to identify the problem:
> I have an abstract base class {{AbstractServiceImpl<E extends Entity>}} that
> defines {{protected final E upsert(E entity)}}. From a subclass inside a
> closure, I try to use {{this::upsert}} as a {{Consumer<DocumentRequest>}}.
> Starting somewhere between 4.0.14 and 4.0.18 (other bugs prevent me from
> bisecting further), an {{IllegalAccessError}} gets introduced at runtime:
> {code}
> java.lang.IllegalAccessError: class
> com.example.doc.DocumentRequestServiceImpl$_openUpload_closure2 tried to
> access protected method 'com.example.base.Entity
> com.example.base.AbstractServiceImpl.upsert(com.example.base.Entity)'
> (com.example.doc.DocumentRequestServiceImpl$_openUpload_closure2 and
> com.example.base.AbstractServiceImpl are in unnamed module of loader 'app')
> {code}
> I've examined the bytecode for both the call site and the method
> implementation, and I can't see a difference in the code generated between
> 4.0.14 and 4.0.18/21. I'm not certain why it works in 4.0.14, but with javac
> I would expect to see a lambda bridge to allow the lambda to access the
> containing-class-visible-but-only-by-inheritance protected method.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)