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 2022/07/05 16:38:00 UTC

[jira] [Updated] (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:all-tabpanel ]

Eric Milles updated GROOVY-9719:
--------------------------------
    Labels: annotations  (was: )

> 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
>              Labels: annotations
>
> 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.20.10#820010)