Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 9+ Compatibility #303

Open
DennisRippinger opened this issue May 21, 2019 · 0 comments
Open

Java 9+ Compatibility #303

DennisRippinger opened this issue May 21, 2019 · 0 comments

Comments

@DennisRippinger
Copy link

DennisRippinger commented May 21, 2019

When the Plugin is executed on a Java 9+ JVM a ClassCastException is thrown:

[ERROR] Could not add schema location to classpath
java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
    at com.phoenixnap.oss.ramlplugin.raml2code.plugin.SpringMvcEndpointGeneratorMojo.getSchemaLocation (SpringMvcEndpointGeneratorMojo.java:477)
    at com.phoenixnap.oss.ramlplugin.raml2code.plugin.SpringMvcEndpointGeneratorMojo.generateEndpoints (SpringMvcEndpointGeneratorMojo.java:261)
    at com.phoenixnap.oss.ramlplugin.raml2code.plugin.SpringMvcEndpointGeneratorMojo.execute (SpringMvcEndpointGeneratorMojo.java:521)
    [...]

The Plugin currently adds the Schema Location to the Classpath by getting the SystemClassLoader as an URLClassLoader, but because the underlying SystemClassLoader is no longer a URLClassLoader this results in an Error:

URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class<?> urlClass = URLClassLoader.class;
Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class });
method.setAccessible(true);
method.invoke(urlClassLoader, new Object[] { new File(resolvedPath).toURI().toURL() });
return "classpath:/"; // since we have added this folder to
// the classpath this
// should be used by the plugin

Several threads about this issue describe a workaround by further specifying the Class#forName usage, but as far as I understand this is not feasible for the current impl where it is assumed that the default classloader knowns the schema files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant