[JAVA-2494] Connection failure from Android Created: 18/Apr/17  Updated: 29/Oct/23  Resolved: 25/Apr/17

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: 3.4.2
Fix Version/s: 3.4.3, 3.5.0

Type: Bug Priority: Major - P3
Reporter: Simon Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Android 5.0


Issue Links:
Duplicate
is duplicated by JAVA-2449 NullPointerException in ClientMetadat... Closed

 Description   

Java driver 3.3.0 works fine and I tried updating to 3.4.2 but the app crashes with the following exception:

java.lang.ExceptionInInitializerError
at com.mongodb.connection.InternalStreamConnectionFactory.<init>(InternalStreamConnectionFactory.java:41)
at com.mongodb.connection.DefaultClusterableServerFactory.create(DefaultClusterableServerFactory.java:68)
at com.mongodb.connection.BaseCluster.createServer(BaseCluster.java:360)
at com.mongodb.connection.SingleServerCluster.<init>(SingleServerCluster.java:54)
at com.mongodb.connection.DefaultClusterFactory.create(DefaultClusterFactory.java:114)
at com.mongodb.Mongo.createCluster(Mongo.java:744)
at com.mongodb.Mongo.createCluster(Mongo.java:728)
at com.mongodb.Mongo.<init>(Mongo.java:293)
at com.mongodb.Mongo.<init>(Mongo.java:288)
at com.mongodb.Mongo.<init>(Mongo.java:284)
at com.mongodb.MongoClient.<init>(MongoClient.java:179)
at com.mongodb.MongoClient.<init>(MongoClient.java:136)
… app code ...
at java.lang.Thread.run(Thread.java:818)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.security.CodeSource java.security.ProtectionDomain.getCodeSource()' on a null object reference
at com.mongodb.connection.ClientMetadataHelper.getDriverVersion(ClientMetadataHelper.java:111)
at com.mongodb.connection.ClientMetadataHelper.getDriverInformation(ClientMetadataHelper.java:201)
at com.mongodb.connection.ClientMetadataHelper.addDriverInformation(ClientMetadataHelper.java:182)
at com.mongodb.connection.ClientMetadataHelper.<clinit>(ClientMetadataHelper.java:64)
at com.mongodb.connection.InternalStreamConnectionFactory.<init>(InternalStreamConnectionFactory.java:41)
at com.mongodb.connection.DefaultClusterableServerFactory.create(DefaultClusterableServerFactory.java:68)
at com.mongodb.connection.BaseCluster.createServer(BaseCluster.java:360)
at com.mongodb.connection.SingleServerCluster.<init>(SingleServerCluster.java:54)
at com.mongodb.connection.DefaultClusterFactory.create(DefaultClusterFactory.java:114)
at com.mongodb.Mongo.createCluster(Mongo.java:744)
at com.mongodb.Mongo.createCluster(Mongo.java:728)
at com.mongodb.Mongo.<init>(Mongo.java:293)
at com.mongodb.Mongo.<init>(Mongo.java:288)
at com.mongodb.Mongo.<init>(Mongo.java:284)
at com.mongodb.MongoClient.<init>(MongoClient.java:179)
at com.mongodb.MongoClient.<init>(MongoClient.java:136)
… app code ...
at java.lang.Thread.run(Thread.java:818)



 Comments   
Comment by Githook User [ 25/Apr/17 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Don't trust the JVM to yield the code source path

JAVA-2494
Branch: 3.4.x
https://github.com/mongodb/mongo-java-driver/commit/45a7f58b6d25b532c14b8bf1b94fcccebac9b72c

Comment by Githook User [ 25/Apr/17 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Don't trust the JVM to yield the code source path

JAVA-2494
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/fd1ff2e97fb8f98cdb7783d587d82b2fd76aaca2

Comment by Ross Lawley [ 25/Apr/17 ]

PR: https://github.com/rozza/mongo-java-driver/pull/186

Comment by Jeffrey Yemin [ 18/Apr/17 ]

In this case it's Class#getProtectionDomain that is returning null rather than ProtectionDomain#getCodeSource, so one step earlier in the call chain.

Comment by Simon [ 18/Apr/17 ]

I tried the latest snapshot version and it does not fix the problem :/

I understand that it is harder to support Android but I think there are great use cases for mongo on Android (we use it for our storemen to control the warehouse system).

Until now every Mongo Java Diver version supported Android. It would be very sad if the platform was dropped now :/

Thanks, Simon

Comment by Ross Lawley [ 18/Apr/17 ]

Marking the NPE as fixed.

Regarding Android support, the Mongo Java Driver doesn't aim to support Android. This is due to limitations with the Android JRE, where some classes that are used by the driver aren't available. One such example is SCRAM-SHA1 authentication.

Ross

Comment by Ross Lawley [ 18/Apr/17 ]

I believe this is a duplicate of JAVA-2449 and the NPE has been fixed in master.

Until the release snapshots are available from Sonatype.

Could you confirm the fix with the latest snapshot?

Generated at Thu Feb 08 08:57:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.