Use of Java 11 leads to java.lang.StringIndexOutOfBoundsException
Brought to you by:
grzegok
You use xstream libg, I do not know which version, but that version has a flaw which leads to exception below.
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.thoughtworks.xstream.XStream.<init>(XStream.java:145)
at com.thoughtworks.xstream.XStream.<init>(XStream.java:181)
at com.thoughtworks.xstream.XStream.<init>(XStream.java:169)
at net.sf.launch4j.config.ConfigPersister.<init>(ConfigPersister.java:73)
at net.sf.launch4j.config.ConfigPersister.<clinit>(ConfigPersister.java:66)
at net.sf.launch4j.Main.main(Main.java:61)
Caused by: java.lang.StringIndexOutOfBoundsException: begin 0, end 3, length 2
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
at java.base/java.lang.String.substring(String.java:1874)
at com.thoughtworks.xstream.core.JVM.getMajorJavaVersion(JVM.java:25)
at com.thoughtworks.xstream.core.JVM.<clinit>(JVM.java:12)
... 6 more
In order to reproduce you can just create Test.java
anywhere inside of the launch4j
project, with such content:
package net.sf.launch4j;
public class Test {
public static void main(String[] args) {
getMajorJavaVersion("11");
}
static final float getMajorJavaVersion(String javaVersion) {
try {
return Float.parseFloat(javaVersion.substring(0, 3));
} catch (NumberFormatException var2) {
return 1.3F;
}
}
}
And run main
method.
Also you can see attached pictures for more info.
This seems to be a problem with the version of xstream included in the 3.12 distro. I was encountering the same problem trying to use launch4j 3.12 on Java 9, but managed to solve the problem after Google pointed me to an older posting on this ticket list. (Oddly, I was not getting this problem with launch4j on Java (1.)8.)
Solution, download a recent binary copy of xstream from http://x-stream.github.io/download.html . (It was 1.4.13 when I just did so.) Take the xstream-X.X.X.jar in that distro and use it to replace the xtream.jar that is in launch4j's lib directory.
Last edit: R. Schmunk 2020-11-05
Updated XStream to 1.4.15.