Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9197

Groovyc fails to correctly propagate classpath entries to javac when run under JDK 11

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.7
    • Fix Version/s: 2.5.9, 3.0.0-rc-2
    • Component/s: None
    • Labels:
      None

      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:

        

      // 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();
          }
      

       

      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.

       

       

        Attachments

        1. groovycCpIssue.zip
          392 kB
          Artsiom Matronkin

          Issue Links

            Activity

              People

              • Assignee:
                emilles Eric Milles
                Reporter:
                artsiom.matronkin Artsiom Matronkin
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m