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

JDepsGeneratorKt.majorJavaVersion throws IndexOutOfBoundsException on OpenJDK 15 #510

Closed
eiiches opened this issue Mar 23, 2021 · 1 comment · Fixed by #511
Closed

JDepsGeneratorKt.majorJavaVersion throws IndexOutOfBoundsException on OpenJDK 15 #510

eiiches opened this issue Mar 23, 2021 · 1 comment · Fixed by #511

Comments

@eiiches
Copy link
Contributor

eiiches commented Mar 23, 2021

Hi, I'm trying to use https://github.com/graknlabs/bazel-distribution, which internally uses rules_kotlin, and got the following exception. The version of rules_kotlin is v1.5.0-alpha-3.

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
        at java.base/java.util.Collections$SingletonList.get(Collections.java:4926)
        at io.bazel.kotlin.builder.tasks.jvm.JDepsGeneratorKt.majorJavaVersion(JDepsGenerator.kt:95)
        at io.bazel.kotlin.builder.tasks.jvm.JDepsGeneratorKt.access$majorJavaVersion(JDepsGenerator.kt:1)
        at io.bazel.kotlin.builder.tasks.jvm.JDepsGenerator.generateJDeps(JDepsGenerator.kt:55)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor$execute$1$$special$$inlined$apply$lambda$3.invoke(KotlinJvmTaskExecutor.kt:123)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor$execute$1$$special$$inlined$apply$lambda$3.invoke(KotlinJvmTaskExecutor.kt:33)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.execute(CompilationTaskContext.kt:148)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.execute(CompilationTaskContext.kt:140)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor$execute$1.invoke(KotlinJvmTaskExecutor.kt:123)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor$execute$1.invoke(KotlinJvmTaskExecutor.kt:33)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.execute(CompilationTaskContext.kt:148)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.execute(CompilationTaskContext.kt:140)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor.execute(KotlinJvmTaskExecutor.kt:56)
        at io.bazel.kotlin.builder.tasks.KotlinBuilder.executeJvmTask(KotlinBuilder.kt:226)
        at io.bazel.kotlin.builder.tasks.KotlinBuilder.apply(KotlinBuilder.kt:129)
        at io.bazel.kotlin.builder.tasks.PersistentWorker.run(BazelWorker.kt:168)
        at io.bazel.kotlin.builder.tasks.BazelWorker.apply(BazelWorker.kt:74)
        at io.bazel.kotlin.builder.KotlinBuilderMain.main(KotlinBuilderMain.java:28)

It seems that we are failing to parse java.version property because the JVM is reporting 15 instead of 15.0 or 15.0.0.

private fun String.majorJavaVersion(): Int {
val (major, minor) = this.trim().split('.')
val parsedMajor = Integer.parseInt(major)
return if (parsedMajor == 1) Integer.parseInt(minor) else parsedMajor
}

According to JEP 223: New Version-String Scheme,

The version number does not include trailing zero elements; i.e., $SECURITY is omitted if it has the value zero, and $MINOR is omitted if both $MINOR and $SECURITY have the value zero.

See Also: JDK-8231384: java.version system property doesn't contain minor/patch version anymore

Additional Info
$ bazel version
Build label: 4.0.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Jan 21 14:04:24 2021 (1611237864)
Build timestamp: 1611237864
Build timestamp as int: 1611237864
$ cat .bazelrc | grep build
build --java_runtime_version=remote_jdk15
build --java_language_version=15
build --javabase=@openjdk15_linux_archive//:runtime
build --host_javabase=@openjdk15_linux_archive//:runtime
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla
http_archive(
    name = "openjdk15_linux_archive",
    build_file_content = """
java_runtime(name = 'runtime', srcs =  glob(['**']), visibility = ['//visibility:public'])
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
""",
    sha256 = "0a38f1138c15a4f243b75eb82f8ef40855afcc402e3c2a6de97ce8235011b1ad",
    strip_prefix = "zulu15.27.17-ca-jdk15.0.0-linux_x64",
    urls = [
        "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-linux_x64.tar.gz",
        "https://cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-linux_x64.tar.gz",
    ],
)
http_archive(
    name = "io_bazel_rules_kotlin",
    urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v1.5.0-alpha-3/rules_kotlin_release.tgz"],
    sha256 = "eeae65f973b70896e474c57aa7681e444d7a5446d9ec0a59bb88c59fc263ff62",
)
@eiiches
Copy link
Contributor Author

eiiches commented Mar 23, 2021

I just upgraded the JDK to 15.0.2 and the issue is gone.

http_archive(
    name = "openjdk15_linux_archive",
    build_file_content = """
java_runtime(name = 'runtime', srcs =  glob(['**']), visibility = ['//visibility:public'])
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
""",
    sha256 = "be8ce1322bc8ded00374bd6ae1b9127d9b3547ccf526b7609bd63cdc49ac58bd",
    strip_prefix = "zulu15.29.15-ca-jdk15.0.2-linux_x64",
    urls = [
        "https://cdn.azul.com/zulu/bin/zulu15.29.15-ca-jdk15.0.2-linux_x64.tar.gz"
    ],
)

eiiches added a commit to eiiches/rules_kotlin that referenced this issue Mar 23, 2021
eiiches added a commit to eiiches/rules_kotlin that referenced this issue Mar 24, 2021
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

Successfully merging a pull request may close this issue.

1 participant