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/09/28 20:35:00 UTC

[jira] [Comment Edited] (GROOVY-9719) Class loading issue when class has annotation referenced to a nested class

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

Eric Milles edited comment on GROOVY-9719 at 9/28/20, 8:34 PM:
---------------------------------------------------------------

I was able to see a loader issue when classpath refers to source directory of A and B.  But when I use the target directory, the classes loaded fine.  I added a test case for reference: https://github.com/apache/groovy/commit/4acca2856baf7483b23bdf9002b35a6bf4501da2


was (Author: emilles):
I was able to see a loader issue when classpath refers to source directory of A and B.  But when I use the output directory, the classes loaded fine.  I added a test case for reference: https://github.com/apache/groovy/commit/4acca2856baf7483b23bdf9002b35a6bf4501da2

> Class loading issue when class has annotation referenced to a nested class
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-9719
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9719
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.3
>            Reporter: Anil Rasouli
>            Priority: Major
>
> A MultipleCompilationErrorsException is thrown when we try to load a class that has a reference to a nested class via annotation.
> Here a small example:
> We have two classes class A and B. Class A has a reference to the nested class of class B (NestedInB) in the annotation.  Class A can not be loaded except the annotation is removed.
>  
> {code:java}
> package pkg2
> import pkg1.B
> class A { 
> @SuppressWarnings(value = [B.NestedInB.NestedProp])  
>   A() {   
>    String name = B.NestedInB.class.getName();      
>    System.out.println(name);           
>    System.out.println(B.NestedInB.NestedProp);  
>   }
> } 
> {code}
> {code:java}
> package pkg1
> import pkg2.A
> public class B {
>       public static final String Prop = "ABCD";
>      B() {
>         A a = new A()
>       }
>   
>      public static class NestedInB {
>         public static final String NestedProp = "ABCD";
>    }
> }
> {code}
> {code:java}
> @Test
> public void test2() throws Exception {
>     final File mainDirectory = new File("Path to the class A and B");
>     URL url = mainDirectory.getAbsoluteFile().toURI().toURL();
>     groovyClassLoader.addURL(url);
>     groovyClassLoader.addClasspath(mainDirectory.getPath());
>     final Class<?> a = groovyClassLoader.loadClass("pkg2.A");
>     a.newInstance();
>     assertNotNull(a);
> }
> {code}



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