Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.36k stars 2k forks source link

[BUG] Error fetching java version when using jdk 17+ #33199

Open thegovind opened 1 year ago

thegovind commented 1 year ago

Describe the bug For openjdk 17+ versions, java version is a string (in System.getProperty("java. Version")) rather than an integer. By trying to parse this in Utils, it's resulting in NumberFormatException

Exception or Stack Trace

com.azure.cosmos.implementation.Utils    : Error while fetching java version
2023-01-27T22:48:06.515327949Z 
2023-01-27T22:48:06.515330384Z java.lang.NumberFormatException: For input string: "19-ea"
2023-01-27T22:48:06.515332001Z  at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67) ~[na:na]
2023-01-27T22:48:06.515333261Z  at java.base/java.lang.Integer.parseInt(Integer.java:668) ~[na:na]
2023-01-27T22:48:06.515334374Z  at java.base/java.lang.Integer.parseInt(Integer.java:784) ~[na:na]
2023-01-27T22:48:06.515335480Z  at com.azure.cosmos.implementation.Utils.getJavaVersion(Utils.java:112) ~[azure-cosmos-4.36.0.jar!/:4.36.0]
2023-01-27T22:48:06.515336880Z  at com.azure.cosmos.implementation.Utils.<clinit>(Utils.java:62) ~[azure-cosmos-4.36.0.jar!/:4.36.0]
2023-01-27T22:48:06.515338203Z  at com.azure.cosmos.implementation.JsonSerializable.<clinit>(JsonSerializable.java:54) ~[azure-cosmos-4.36.0.jar!/:4.36.0]
2023-01-27T22:48:06.515339488Z  at com.azure.cosmos.implementation.RxDocumentClientImpl.<clinit>(RxDocumentClientImpl.java:115) ~[azure-cosmos-4.36.0.jar!/:4.36.0]

To Reproduce Run with openjdk:17 or higher as base image in Docker

Code Snippet https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Utils.java#L115

Expected behavior Parse the java version accurately without any error in stacktrace

Setup (please complete the following information):

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

ghost commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kushagraThapar, @TheovanKraay

kushagraThapar commented 1 year ago

@aayush3011 - please take a look at this, thanks!

alzimmermsft commented 1 year ago

@thegovind, is the version of the JDK/JRE you're using an early access version? Based on this issue it appears to be following the version format mentioned for early access builds defined in JEP 223.

@kushagraThapar / @aayush3011 based on the mentioned JEP it looks like this can be fixed by checking the first part to end with -ea before continuing parsing.

kushagraThapar commented 1 year ago

Thanks @alzimmermsft for the suggestion. @aayush3011 can you please follow up on this.