Skip to content

Java 9+ Compatibility #303

Description

@DennisRippinger

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions