groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-9005) SomeClass.groovy: -1: Access to java.lang.Object#this is forbidden @ line -1, column -1
Date Wed, 20 Feb 2019 17:58:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-9005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16773241#comment-16773241
] 

Eric Milles edited comment on GROOVY-9005 at 2/20/19 5:57 PM:
--------------------------------------------------------------

Sure, I would like to see the bug fixed as well.  Just trying to hone in on where exactly
the bug lies.

You could isolate the anonymous inner creation to a method.  That could be tagged @CompileDynamic
if needed.
{code:groovy}
@CompileStatic
class A extends A1 {
    Map<String, Object> getInnerObject() {
        Map<String, Object> commands = getBaseMap()
        commands.put("name", newCallable())
        return commands
    }
    // could be @CompileDynamic if needed
    Callable<String> newCallable() {
      new Callable<String>() {
        @Override
        String call() {
          getObject().toString() // can be qualified with "A.this." if needed; this may eliminate
the error
        }
      }
    }
}
{code}


was (Author: emilles):
Sure, I would like to see the bug fixed as well.  Just trying to hone in on where exactly
the bug lies.

You could isolate the anonymous inner creation to a method.  That could be tagged @CompileDynamic
if needed.
{code:groovy}
@CompileStatic
class A extends A1 {
    Map<String, Object> getInnerObject() {
        Map<String, Object> commands = getBaseMap()
        commands.put("name", newCallable())
        return commands
    }
    // could be @CompileDynamic if needed
    Callable<String> newCallable() {
      new Callable<String>() {
        @Override
        String call() {
          def someValue = getObject().toString()
          return someValue
        }
      }
    }
}
{code}

> SomeClass.groovy: -1: Access to java.lang.Object#this is forbidden @ line -1, column
-1
> ---------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9005
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9005
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.5.6
>            Reporter: Devin Rosenbauer
>            Priority: Major
>         Attachments: GROOVY-9005.zip
>
>
> I'm receiving the above error when attempting to compile certain classes that have @CompileStatic
on either the class or a method within a dynamically compiled class. The project is a cross-compiled
Java / Groovy project with all classes of both types defined in the "groovy" structure. The
error can be reproduced when a Groovy class extends a Java class which extends a Groovy class,
then a method in the Java class is called from an inner class of the Groovy class.
> The simplest case I can derive to reproduce the failure is attached.
> A is the class which fails to compile. A1 and A2 are the Java and Groovy superclasses,
respectively.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message