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 version check throws StringIndexOutOfBoundsException on exact major versions #439

Closed
ato opened this issue Sep 30, 2021 · 0 comments
Closed
Labels

Comments

@ato
Copy link
Collaborator

ato commented Sep 30, 2021

Trying out Heritrix on the first JDK 17 release encountered this exception:

$ java -version
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment Temurin-17+35 (build 17+35)
OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)

java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 2
    at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4601)
    at java.base/java.lang.String.substring(String.java:2704)
    at org.archive.crawler.Heritrix.instanceMain(Heritrix.java:198)
    at org.archive.crawler.selftest.SelfTestBase.startHeritrix(SelfTestBase.java:207)
    at org.archive.crawler.selftest.SelfTestBase.open(SelfTestBase.java:113)
    at org.archive.crawler.selftest.SelfTestBase.testSomething(SelfTestBase.java:151)

I think we should just remove the version check. It's ensuring we're running Java 1.6 or later, but since we target Java 8 for compilation the class can't even be loaded on the old JVMs this check would trigger on, so this code is effectively unreachable.

// ensure using java 1.6+ before hitting a later cryptic error
String version = System.getProperty("java.version");
float floatVersion = Float.valueOf(version.substring(0,version.indexOf('.',2)));
if(floatVersion<1.6) {
System.err.println("Heritrix (as of version 3) requires Java 1.6 or higher.");
System.err.println("You attempted to launch with: "+version);
System.err.println("Please try again with a later Java.");
System.exit(1);
}

@ato ato added the bug label Sep 30, 2021
@ato ato closed this as completed in 17d760a Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant