[JAVA-4656] getJavaMajorVersion() fails with version tag 18-ea Created: 21/Jun/22  Updated: 28/Oct/23  Resolved: 23/Jun/22

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: None
Fix Version/s: 4.7.1

Type: Bug Priority: Minor - P4
Reporter: Magnus Sulland Assignee: Valentin Kavalenka
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed

 Description   

Summary

Using the first release of java 18, it identifies itself as version 18-ea. This creates a problem in the method getJavaMajorVersion where - is not supported. This then creates a number exception.

 

https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/main/com/mongodb/internal/connection/tlschannel/util/Util.java

 public static int getJavaMajorVersion() {
    String version = System.getProperty("java.version");
    if (version.startsWith("1."))

{       version = version.substring(2, 3);     }

else {
      int dot = version.indexOf(".");
      if (dot != -1)

{         version = version.substring(0, dot);       }

    }
    return Integer.parseInt(version);
  }

 

 

Exception:

 
com.mongodb.MongoInternalException: Opening the TlsChannelStream failed
 
 
33
at com.mongodb.internal.connection.AsynchronousChannelStream$FutureAsyncCompletionHandler.get(AsynchronousChannelStream.java:328) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
32
at com.mongodb.internal.connection.AsynchronousChannelStream$FutureAsyncCompletionHandler.getOpen(AsynchronousChannelStream.java:304) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
31
at com.mongodb.internal.connection.AsynchronousChannelStream.open(AsynchronousChannelStream.java:125) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
30
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:180) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
29
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
28
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:152) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
27
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
 
 
26
Caused by: java.lang.ExceptionInInitializerError: null
 
 
25
at com.mongodb.internal.connection.tlschannel.TlsChannelBuilder.<init>(TlsChannelBuilder.java:37) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
24
at com.mongodb.internal.connection.tlschannel.ClientTlsChannel$Builder.<init>(ClientTlsChannel.java:45) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
23
at com.mongodb.internal.connection.tlschannel.ClientTlsChannel$Builder.<init>(ClientTlsChannel.java:40) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
22
at com.mongodb.internal.connection.tlschannel.ClientTlsChannel.newBuilder(ClientTlsChannel.java:87) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
21
at com.mongodb.connection.TlsChannelStreamFactoryFactory$TlsChannelStream.lambda$openAsync$0(TlsChannelStreamFactoryFactory.java:236) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
20
at com.mongodb.connection.TlsChannelStreamFactoryFactory$SelectorMonitor.lambda$start$0(TlsChannelStreamFactoryFactory.java:141) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
19
... 1 common frames omitted
 
 
18
Caused by: java.lang.NumberFormatException: For input string: "18-ea"
 
 
17
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67) ~[na:na]
 
 
16
at java.base/java.lang.Integer.parseInt(Integer.java:668) ~[na:na]
 
 
15
at java.base/java.lang.Integer.parseInt(Integer.java:784) ~[na:na]
 
 
14
at com.mongodb.internal.connection.tlschannel.util.Util.getJavaMajorVersion(Util.java:56) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
13
at com.mongodb.internal.connection.tlschannel.util.DirectBufferDeallocator.<init>(DirectBufferDeallocator.java:109) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
12
at com.mongodb.internal.connection.tlschannel.DirectBufferAllocator.<init>(DirectBufferAllocator.java:37) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
11
at com.mongodb.internal.connection.tlschannel.TlsChannel.<clinit>(TlsChannel.java:70) ~[mongodb-driver-core-4.4.2.jar:na]
 
 
10
... 7 common frames omitted

How to Reproduce

Using java with the latest  openjdk:18-alpine docker image.

 

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by Valentin Kavalenka [ 23/Jun/22 ]

Hi magnus@apperiet.no,

Thank you for taking time to report the bug. The fix will be released in 4.6.2.

Comment by Githook User [ 23/Jun/22 ]

Author:

{'name': 'Valentin Kovalenko', 'email': 'valentin.kovalenko@mongodb.com', 'username': 'stIncMale'}

Message: Fix `tlschannel.util.Util.getJavaMajorVersion` (#969)

This is a combination of a manual cherry-pick and squash of the following commits:

and a small fix on top of that.

JAVA-4656
Branch: 4.6.x
https://github.com/mongodb/mongo-java-driver/commit/795ddcf41babd1839ba4b399273713ecaf215205

Comment by Githook User [ 23/Jun/22 ]

Author:

{'name': 'Valentin Kovalenko', 'email': 'valentin.kovalenko@mongodb.com', 'username': 'stIncMale'}

Message: Fix `tlschannel.util.Util.getJavaMajorVersion` (#969)

This is a combination of a manual cherry-pick and squash of the following commits:

and a small fix on top of that.

JAVA-4656
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/1375eee07cd0d99745feba62dd329e1abaf418bf

Generated at Thu Feb 08 09:02:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.