Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4656

getJavaMajorVersion() fails with version tag 18-ea

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.7.1
    • Affects Version/s: None
    • Component/s: Connection Management
    • None
    • Fully Compatible
    • Not Needed

      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.

            Assignee:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Reporter:
            magnus@apperiet.no Magnus Sulland
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: