You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/08/18 15:36:00 UTC
[jira] [Commented] (GROOVY-9695) Regression for accessing private
static constants in closures from Parent Classes
[ https://issues.apache.org/jira/browse/GROOVY-9695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17179706#comment-17179706 ]
Eric Milles commented on GROOVY-9695:
-------------------------------------
I'll have to look closer, but when you extend a class you change the nature of "this" and there are open issues for this same thing when the field is an instance field. As a workaround, you can add a qualifier to "PATTERNS" or make the field protected or add @CompileStatic to the method. The static compiler path adds private access bridge methods which the dynamic compiler does not.
GROOVY-5438
> Regression for accessing private static constants in closures from Parent Classes
> ---------------------------------------------------------------------------------
>
> Key: GROOVY-9695
> URL: https://issues.apache.org/jira/browse/GROOVY-9695
> Project: Groovy
> Issue Type: Bug
> Reporter: Leonard Brünings
> Priority: Major
> Fix For: 2.5.13
>
>
> The following code worked in 2.5.12, in 2.5.13 {{testChildClass}} fails with {{groovy.lang.MissingPropertyException: No such property: PATTERNS for class: Child}}
> [~emilles] probably related to the changes mentioned here GROOVY-9665
> {code:groovy}
> class Example {
> @Test
> void testBaseClass() {
> new Base().check("FooSpec")
> }
> @Test
> void testChildClass() {
> new Child().check("FooSpec")
> }
> }
> class Base {
> private static final List<Pattern> PATTERNS = [~/.*Test/, ~/.*Spec/]
> def check(String str) {
> List failures = []
> def result = PATTERNS.findResult { Pattern pattern ->
> if (pattern.matcher(str).matches()) {
> return str
> } else {
> failures.add("Pattern ${PATTERNS.indexOf(pattern)} did not match")
> }
> }
> if (!result) {
> throw new IllegalArgumentException("Did Match no pattern: "+failures.join(", "))
> }
> return result
> }
> }
> class Child extends Base {
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)