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

Fix java.version parsing (#510) #511

Merged
merged 1 commit into from
Mar 24, 2021

Conversation

eiiches
Copy link
Contributor

@eiiches eiiches commented Mar 23, 2021

Fixes #510

We can't always assume this.trim().split('.') to have 3 elements, because java.version does not include trailing zero elements. In other words, java.version can be a single number like 11 or 15. This change fixes IndexOutOfBoundsException caused by the wrong assumption.

References:

@eiiches
Copy link
Contributor Author

eiiches commented Mar 23, 2021

I wasn't sure if I should add tests for this. Adding tests would require changing the visibility of the method to internal and modifying kt_bootstrap_library rule to support "associates" similar to the one supported by kt_jvm_library.

val parsedMajor = Integer.parseInt(major)
return if (parsedMajor == 1) Integer.parseInt(minor) else parsedMajor
if (parsedMajor != 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be rewritten in the former style:

 return if (parsedMajor == 1) Integer.parseInt(elements[1]) else parsedMajor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. Fixed as suggested.

@eiiches eiiches force-pushed the fix-java-version-parsing branch from 51b08b1 to b1cc604 Compare March 24, 2021 02:48
@restingbull restingbull merged commit 5357ac1 into bazelbuild:master 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 this pull request may close these issues.

JDepsGeneratorKt.majorJavaVersion throws IndexOutOfBoundsException on OpenJDK 15
3 participants