Java 9, 10 compilation fails: sun.misc.URLClassPath missing

Description

Compiling the Git head under Java 10.0.1 yields

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project izpack-test-common: Compilation failure: Compilation failure:
[ERROR] /Users/cxh/src/izpack/izpack-test-common/src/main/java/com/izforge/izpack/test/util/ClassUtils.java:[3,16] cannot find symbol
[ERROR] symbol: class URLClassPath
[ERROR] location: package sun.misc
[ERROR] /Users/cxh/src/izpack/izpack-test-common/src/main/java/com/izforge/izpack/test/util/ClassUtils.java:[27,13] cannot find symbol
[ERROR] symbol: class URLClassPath
[ERROR] location: class com.izforge.izpack.test.util.ClassUtils
[ERROR] /Users/cxh/src/izpack/izpack-test-common/src/main/java/com/izforge/izpack/test/util/ClassUtils.java:[27,33] cannot find symbol
[ERROR] symbol: class URLClassPath
[ERROR] location: class com.izforge.izpack.test.util.ClassUtils
[ERROR] /Users/cxh/src/izpack/izpack-test-common/src/main/java/com/izforge/izpack/test/util/ClassUtils.java:[28,31] cannot find symbol
[ERROR] symbol: class URLClassPath
[ERROR] location: class com.izforge.izpack.test.util.ClassUtils
[ERROR] /Users/cxh/src/izpack/izpack-test-common/src/main/java/com/izforge/izpack/test/util/ClassUtils.java:[33,33] cannot find symbol
[ERROR] symbol: class URLClassPath
[ERROR] location: class com.izforge.izpack.test.util.ClassUtils

izpack/izpack-test-common/src/main/java/com/izforge/izpack/test/util/ClassUtils.java defines an unloadLastJar() method:

public static void unloadLastJar()
{
try
{
URLClassLoader systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Field ucpField = URLClassLoader.class.getDeclaredField("ucp");
ucpField.setAccessible(true);
URLClassPath ucp = (URLClassPath) ucpField.get(systemClassLoader);
Field pathField = URLClassPath.class.getDeclaredField("path");
pathField.setAccessible(true);
ArrayList<URL> path = (ArrayList<URL>) pathField.get(ucp);
path.remove(path.size() - 1);

Field loaderField = URLClassPath.class.getDeclaredField("loaders");
loaderField.setAccessible(true);
ArrayList loaders = (ArrayList) loaderField.get(ucp);
loaders.remove(loaders.size() - 1);
}
catch (Exception e)
{
throw new IllegalStateException(e);
}
}

unloadLastJar() is used by izpack-test/src/test/java/com/izforge/izpack/compiler/container/AbstractTestInstallationContainer.java:

import com.izforge.izpack.test.junit.UnloadJarRule;
...
@Rule
public UnloadJarRule unloadJarRule = new UnloadJarRule();

The following classes extend AbstractTestInstallationContainer:

./izpack-test/src/test/java/com/izforge/izpack/compiler/container/TestAutomatedInstallationContainer.java
./izpack-test/src/test/java/com/izforge/izpack/compiler/container/TestGUIInstallationContainer.java
./izpack-test/src/test/java/com/izforge/izpack/compiler/container/TestConsoleInstallationContainer.java
./izpack-test/src/test/java/com/izforge/izpack/compiler/container/AbstractTestInstallationContainer.java
./izpack-test/src/test/java/com/izforge/izpack/compiler/container/AbstractTestInstallationContainer.java

So I guess what is happening here is that there is a JUnit @Rule defined to unload the last jar.

The fix would be to define code that would do something similar.

Environment

Mac OS 10.13.4 (High Sierra)

bash-3.2$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

Status

Assignee

Unassigned

Reporter

Christopher Brooks

Impact

None

Components

Affects versions

Priority

Medium
Configure