Java 9+ Issues with URLClassLoader

Description

Hi

I don't know where to post this issue but it seems the new version of Java doesn't play very well with jasperstarter

```
./jasperstarter process /home/user/hello-wiorld.jasper -f pdf -r ~/Desktop -P hello=1
Exception in thread "main" java.lang.ClassCastException: jdk.internal.loader.ClassLoaders$AppClassLoader (in module: java.base) cannot be cast to java.net.URLClassLoader (in module: java.base)
at de.cenote.tools.classpath.ApplicationClasspath.add(ApplicationClasspath.java:72)
at de.cenote.tools.classpath.ApplicationClasspath.add(ApplicationClasspath.java:62)
at de.cenote.tools.classpath.ApplicationClasspath.addJars(ApplicationClasspath.java:127)
at de.cenote.tools.classpath.ApplicationClasspath.addJarsRelative(ApplicationClasspath.java:142)
at de.cenote.jasperstarter.App.processReport(App.java:169)
at de.cenote.jasperstarter.App.main(App.java:102)

```

Environment

  • Ubuntu 16.04 (64bit)

  • openjdk version "9-internal"
    OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
    OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)

Activity

Show:
Volker Voßkämper
February 23, 2017, 1:22 PM

Hi Ricardo,

this seems to be a general problem with Java9 which affects other applications to.
See https://community.oracle.com/thread/4011800

Thank you for reporting
Regards
Volker

Volker Voßkämper
March 7, 2017, 2:38 PM

Hi Ricardo,

I just enabled a Java9 build pipeline.
Interestingly a full build works if tests are skipped.

But instead of a nice exception I get a core dump on tests:

#(...)
fill from jsondatasource
#

  1. A fatal error has been detected by the Java Runtime Environment:
    #

  2. SIGSEGV (0xb) at pc=0x00007fea398ce009, pid=626, tid=627
    #

  3. JRE version: OpenJDK Runtime Environment (9.0) (build 9-internal+0-2016-04-14-195246.buildd.src)

  4. Java VM: OpenJDK 64-Bit Server VM (9-internal+0-2016-04-14-195246.buildd.src, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)

  5. Problematic frame:

  6. C [libjava.so+0x1d009] JNU_GetEnv+0x19
    #

  7. Core dump will be written.
    #(...)

Ricardo Pascua
March 8, 2017, 7:08 AM

Hi Volker,

Really I don't have any idea with Java but thanks for your effort in your project.

Regards,
Ricardo

Volker Voßkämper
November 4, 2019, 4:00 PM

This issue first popped up with Java9 but Java10, Java11 and Java12 worked for some time.

Unfortunately there was no test that invoked the ApplicationClasspath.add function.

Now, any Java Version >= Java9 throws a ClassCastException when trying to cast the systemClassLoader to an URLClassLoader.

Thanks to Rafael for pointing out the details in the disscussion forum.
See: https://blog.codefx.org/java/java-11-migration-guide/#Casting-To-URL-Class-Loader

Volker Voßkämper
November 4, 2019, 4:02 PM

Assignee

Volker Voßkämper

Reporter

Ricardo Pascua

Labels

Components

Fix versions

Affects versions

Priority

Major
Configure