You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Artsiom Matronkin (JIRA)" <ji...@apache.org> on 2019/07/18 08:56:00 UTC

[jira] [Updated] (GROOVY-9197) Groovyc fails to correctly propagate classpath entries to javac when run under JDK 11

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

Artsiom Matronkin updated GROOVY-9197:
--------------------------------------
    Description: 
*Repro Steps:*
 * unpack attached zip
 * ensure CompileAntScript.xml references the version of groovy you have locally
 * ensure JAVA_HOME is referencing JDK 11
 * execute CompileAntScript.xml via Ant (ensure it is executed by JDK 11)

*Actual Result:* 

_[compile] C:\dev\workspace\search0625_11\groovycIssue\src\org_
 _[compile] \groovy\issue\TestCompile.java:3: error: package org.apache.commons.lang3 does not exist_
 _[compile] import static org.apache.commons.lang3_
 _[compile] .StringUtils.isEmpty;_

 

Try running same ant script via JDK 8 and it will compile successfully.

 

*Investigation Details:*

Looking into groovy codebase it seems there is a bug/issue in how org.codehaus.groovy.tools.javac.JavacJavaCompiler.java accumulates classpath entries which should be passed to javac:

  
{code:java}
// append classpath if not already defined
if (!hadClasspath) {
    // add all classpaths that compilation unit sees
    List<String> paths = new ArrayList<String>(config.getClasspath());
    ClassLoader cl = parentClassLoader;
    while (cl != null) {
        if (cl instanceof URLClassLoader) {
            for (URL u : ((URLClassLoader) cl).getURLs()) {
                try {
                    paths.add(new File(u.toURI()).getPath());
                } catch (URISyntaxException e) {
                    // ignore it
                }
            }
        }
        cl = cl.getParent();
    }
{code}
 

 

 

It iterates over hierarchy of classloaders and *assumes AppClassLoader is an instance of URLClassLoader*. This assumption was correct in Java 8 but is not correct in Java 11 ([https://blog.codefx.org/java/java-11-migration-guide/]   - ‘Casting to URLClassLoader’ chapter). Thus most of jars are not passed to javac as classpath and compilation fails.

 

 

  was:
*Repro Steps:*
 * unpack attached zip
 * ensure CompileAntScript.xml references the version of groovy you have locally
 * ensure JAVA_HOME is referencing JDK 11
 * execute CompileAntScript.xml via Ant (ensure it is executed by JDK 11)

*Actual Result:* 

 _[compile] C:\dev\workspace\search0625_11\groovycIssue\src\org_
 _[compile] \groovy\issue\TestCompile.java:3: error: package org.apache.commons.lang3 does not exist_
 _[compile] import static org.apache.commons.lang3_
 _[compile] .StringUtils.isEmpty;_

 

Try running same ant script via JDK 8 and it will compile successfully.

 

*Investigation Details:*

Looking into groovy codebase it seems there is a bug/issue in how org.codehaus.groovy.tools.javac.JavacJavaCompiler.java accumulates classpath entries which should be passed to javac:

  

{color:#808080}// append classpath if not already defined
 {color}{color:#cc7832}if {color}{color:#a9b7c6}(!hadClasspath) {
     {color}{color:#808080}// add all classpaths that compilation unit sees
     {color}{color:#a9b7c6}List<String> paths = {color}{color:#cc7832}new {color}{color:#a9b7c6}ArrayList<String>({color}{color:#9876aa}config{color}{color:#a9b7c6}.getClasspath()){color}{color:#cc7832};
     {color}{color:#a9b7c6}ClassLoader cl = parentClassLoader{color}{color:#cc7832};
     while {color}{color:#a9b7c6}(cl != {color}{color:#cc7832}null{color}{color:#a9b7c6}) {
         {color}{color:#cc7832}if {color}{color:#a9b7c6}(cl {color}{color:#cc7832}instanceof {color}{color:#a9b7c6}URLClassLoader) {
             {color}{color:#cc7832}for {color}{color:#a9b7c6}(URL u : ((URLClassLoader) cl).getURLs()) {
                 {color}{color:#cc7832}try {color}{color:#a9b7c6}{
                     paths.add({color}{color:#cc7832}new {color}{color:#a9b7c6}File(u.toURI()).getPath()){color}{color:#cc7832};
                 {color}{color:#a9b7c6}} {color}{color:#cc7832}catch {color}{color:#a9b7c6}(URISyntaxException e) {
                     {color}{color:#808080}// ignore it
                 {color}{color:#a9b7c6}}
             }
         }
         cl = cl.getParent(){color}{color:#cc7832};
     {color}{color:#a9b7c6}}{color}

 

It iterates over hierarchy of classloaders and *assumes AppClassLoader is an instance of URLClassLoader*. This assumption was correct in Java 8 but is not correct in Java 11 ([https://blog.codefx.org/java/java-11-migration-guide/]   - ‘Casting to URLClassLoader’ chapter). Thus most of jars are not passed to javac as classpath and compilation fails.

 

 


> Groovyc fails to correctly propagate classpath entries to javac when run under JDK 11
> -------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9197
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9197
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.7
>            Reporter: Artsiom Matronkin
>            Priority: Major
>         Attachments: groovycCpIssue.zip
>
>
> *Repro Steps:*
>  * unpack attached zip
>  * ensure CompileAntScript.xml references the version of groovy you have locally
>  * ensure JAVA_HOME is referencing JDK 11
>  * execute CompileAntScript.xml via Ant (ensure it is executed by JDK 11)
> *Actual Result:* 
> _[compile] C:\dev\workspace\search0625_11\groovycIssue\src\org_
>  _[compile] \groovy\issue\TestCompile.java:3: error: package org.apache.commons.lang3 does not exist_
>  _[compile] import static org.apache.commons.lang3_
>  _[compile] .StringUtils.isEmpty;_
>  
> Try running same ant script via JDK 8 and it will compile successfully.
>  
> *Investigation Details:*
> Looking into groovy codebase it seems there is a bug/issue in how org.codehaus.groovy.tools.javac.JavacJavaCompiler.java accumulates classpath entries which should be passed to javac:
>   
> {code:java}
> // append classpath if not already defined
> if (!hadClasspath) {
>     // add all classpaths that compilation unit sees
>     List<String> paths = new ArrayList<String>(config.getClasspath());
>     ClassLoader cl = parentClassLoader;
>     while (cl != null) {
>         if (cl instanceof URLClassLoader) {
>             for (URL u : ((URLClassLoader) cl).getURLs()) {
>                 try {
>                     paths.add(new File(u.toURI()).getPath());
>                 } catch (URISyntaxException e) {
>                     // ignore it
>                 }
>             }
>         }
>         cl = cl.getParent();
>     }
> {code}
>  
>  
>  
> It iterates over hierarchy of classloaders and *assumes AppClassLoader is an instance of URLClassLoader*. This assumption was correct in Java 8 but is not correct in Java 11 ([https://blog.codefx.org/java/java-11-migration-guide/]   - ‘Casting to URLClassLoader’ chapter). Thus most of jars are not passed to javac as classpath and compilation fails.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)