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

Marcin Zajaczkowski updated GROOVY-10040:
-----------------------------------------
    Description: 
I've bumped into that problem writing regression tests for using 
@AnnotationCollector in Spock to achieve meta-annotation support. A custom 
annotation accepting Clusure is problematic with @AnnotationCollector. It 
compiles file with groovyc, but not with ClassLoader (which is used by Spock's 
EmbeddedSpecCompiler).

The problem can be simply reproduced with `GroovyClassLoader`:
{code:java}
package foobar

import groovy.transform.AnnotationCollector

class CustomCompiler {
  final GroovyClassLoader loader = new GroovyClassLoader(getClass().classLoader)

  static void main(String[] args) {
    new CustomCompiler().compile()
  }

  void compile() {
    Class clazz = loader.parseClass("""
//@${CustomCompiler.class.packageName}.RetryCustom //works fine
@${CustomCompiler.class.packageName}.MetaCustom 
//MultipleCompilationErrorsException exception
class Foo {
 void foo() {
 }
}
""")
    assert clazz
  }
}

@RetryCustom(1)
@RequiresCustom({ 1 == 1 })
@AnnotationCollector
@interface MetaCustom {
}

@interface RequiresCustom {
  Class<? extends Closure> value()
}

@interface RetryCustom {
  int value()
}
{code}
which results in:
{code:java}
Exception in thread "main" 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script_45e27a459ca58d9b86efd544e2929b39.groovy: -1: Only classes and closures 
can be used for attribute 'value' in @foobar.RequiresCustom
 @ line -1, column -1.
1 error
at 
org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:295)
 at 
org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:984)
 at 
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)
 at 
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
 at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389)
 at 
groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332)
 at 
org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
 at 
org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:314)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:257)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native 
Method)
 at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at 
org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
 at 
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap.invoke(PojoMetaMethodSite.java:203)
 at 
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
 at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
 at foobar.CustomCompiler.compile(CustomCompiler.groovy:15)
 at foobar.CustomCompiler$compile.call(Unknown Source)
 at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
 at foobar.CustomCompiler.main(CustomCompiler.groovy:10)
{code}
 

If it really happens only with `GroovyClassLoader`,it is a minor problem. 
However, I believe, I might have observed that occasionally while compiling 
with Idea 2020.3 (but I'm not able to reproduce it right now and I might 
confuse parameters).

  was:
I've bumped into that problem writing regression tests for using 
@AnnotationCollector in Spock to achieve meta-annotation support. A custom 
annotation accepting Clusure is problematic with @AnnotationCollector. It 
compiles file with groovyc, but not with ClassLoader (which is used by Spock's 
EmbeddedSpecCompiler).

The problem can be simply reproduced with `GroovyClassLoader`:
{code:java}
package foobar

import groovy.transform.AnnotationCollector

class CustomCompiler {
final GroovyClassLoader loader = new GroovyClassLoader(getClass().classLoader)
static void main(String[] args) {
  new CustomCompiler().compile()
}
void compile() {
  loader.clearCache()
  Class clazz = loader.parseClass("""
//@${CustomCompiler.class.packageName}.RetryCustom //works fine
@${CustomCompiler.class.packageName}.MetaCustom 
//MultipleCompilationErrorsException exception
class Foo {
 void foo() {
 }
}
""")
  assert clazz
  }
}

@RetryCustom(1)
@RequiresCustom({ 1 == 1 })
@AnnotationCollector
@interface MetaCustom {
}

@interface RequiresCustom {
  Class<? extends Closure> value()
}

@interface RetryCustom {
  int value()
}
{code}
which results in:
{code:java}
Exception in thread "main" 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script_45e27a459ca58d9b86efd544e2929b39.groovy: -1: Only classes and closures 
can be used for attribute 'value' in @foobar.RequiresCustom
 @ line -1, column -1.
1 error
at 
org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:295)
 at 
org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:984)
 at 
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)
 at 
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
 at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389)
 at 
groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332)
 at 
org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
 at 
org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:314)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:257)
 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native 
Method)
 at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at 
org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
 at 
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap.invoke(PojoMetaMethodSite.java:203)
 at 
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
 at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
 at foobar.CustomCompiler.compile(CustomCompiler.groovy:15)
 at foobar.CustomCompiler$compile.call(Unknown Source)
 at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
 at foobar.CustomCompiler.main(CustomCompiler.groovy:10)
{code}
 

If it really happens only with `GroovyClassLoader`,it is a minor problem. 
However, I believe, I might have observed that occasionally while compiling 
with Idea 2020.3 (but I'm not able to reproduce it right now and I might 
confuse parameters).


> @AnnotationCollector - Only classes and closures can be used for attribute 
> 'value' in ...
> -----------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10040
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10040
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 3.0.7
>         Environment: Groovy 3.0.7
>            Reporter: Marcin Zajaczkowski
>            Priority: Minor
>
> I've bumped into that problem writing regression tests for using 
> @AnnotationCollector in Spock to achieve meta-annotation support. A custom 
> annotation accepting Clusure is problematic with @AnnotationCollector. It 
> compiles file with groovyc, but not with ClassLoader (which is used by 
> Spock's EmbeddedSpecCompiler).
> The problem can be simply reproduced with `GroovyClassLoader`:
> {code:java}
> package foobar
> import groovy.transform.AnnotationCollector
> class CustomCompiler {
>   final GroovyClassLoader loader = new 
> GroovyClassLoader(getClass().classLoader)
>   static void main(String[] args) {
>     new CustomCompiler().compile()
>   }
>   void compile() {
>     Class clazz = loader.parseClass("""
> //@${CustomCompiler.class.packageName}.RetryCustom //works fine
> @${CustomCompiler.class.packageName}.MetaCustom 
> //MultipleCompilationErrorsException exception
> class Foo {
>  void foo() {
>  }
> }
> """)
>     assert clazz
>   }
> }
> @RetryCustom(1)
> @RequiresCustom({ 1 == 1 })
> @AnnotationCollector
> @interface MetaCustom {
> }
> @interface RequiresCustom {
>   Class<? extends Closure> value()
> }
> @interface RetryCustom {
>   int value()
> }
> {code}
> which results in:
> {code:java}
> Exception in thread "main" 
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> Script_45e27a459ca58d9b86efd544e2929b39.groovy: -1: Only classes and closures 
> can be used for attribute 'value' in @foobar.RequiresCustom
>  @ line -1, column -1.
> 1 error
> at 
> org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:295)
>  at 
> org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:984)
>  at 
> org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)
>  at 
> org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
>  at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389)
>  at 
> groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332)
>  at 
> org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
>  at 
> org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
>  at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330)
>  at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:314)
>  at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:257)
>  at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
>  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native 
> Method)
>  at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.base/java.lang.reflect.Method.invoke(Method.java:566)
>  at 
> org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
>  at 
> org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap.invoke(PojoMetaMethodSite.java:203)
>  at 
> org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
>  at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
>  at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
>  at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
>  at foobar.CustomCompiler.compile(CustomCompiler.groovy:15)
>  at foobar.CustomCompiler$compile.call(Unknown Source)
>  at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
>  at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
>  at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
>  at foobar.CustomCompiler.main(CustomCompiler.groovy:10)
> {code}
>  
> If it really happens only with `GroovyClassLoader`,it is a minor problem. 
> However, I believe, I might have observed that occasionally while compiling 
> with Idea 2020.3 (but I'm not able to reproduce it right now and I might 
> confuse parameters).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to