[JAVA-1283] java.lang.IllegalAccessError on redeployment using async driver Created: 17/Jun/14  Updated: 14/Oct/17  Resolved: 29/Sep/17

Status: Closed
Project: Java Driver
Component/s: Async
Affects Version/s: 3.0.0
Fix Version/s: None

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

Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
OS X 10.9.3
vert.x 2.1


Attachments: Zip Archive JAVA-1283.zip     Zip Archive JAVA-1283_java_only.zip    

 Description   

I have a groovy class, which runs in vert.x that makes use of the java driver:

 
	final EventBus eb
	final Container container
	final Logger logger
	final MongoClient mongo
	final MongoDatabase db
 
	public Service(EventBus eb, Container container) {
		this.eb = eb
		this.container = container
		logger = container.logger
 
		mongo = MongoClients.create(new MongoClientURI('mongodb://localhost:27017'), MongoClientOptions.builder().build())
		logger.info('got mongo client: ' + mongo)
		db = mongo.getDatabase('mydb')
		logger.info('got db: ' + db)
	}
 
	public void terminate() {
		mongo.close()
	}

In case vert.x redeploys the module containing this class I see the following exception:

got mongo client: org.mongodb.async.MongoClientImpl@6e16e721
got db: org.mongodb.async.MongoDatabaseImpl@169e0757
Exception in thread "Thread-6" java.lang.IllegalAccessError: tried to access class org.mongodb.connection.AsynchronousSocketChannelStream$AsyncWritableByteChannelAdapter$1$1 from class org.mongodb.connection.AsynchronousSocketChannelStream$AsyncWritableByteChannelAdapter$1
	at org.mongodb.connection.AsynchronousSocketChannelStream$AsyncWritableByteChannelAdapter$1.completed(AsynchronousSocketChannelStream.java:183)
	at org.mongodb.connection.AsynchronousSocketChannelStream$AsyncWritableByteChannelAdapter$1.completed(AsynchronousSocketChannelStream.java:180)
	at org.mongodb.connection.AsynchronousSocketChannelStream$2.completed(AsynchronousSocketChannelStream.java:140)
	at org.mongodb.connection.AsynchronousSocketChannelStream$2.completed(AsynchronousSocketChannelStream.java:137)
	at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126)
	at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:278)
	at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:198)
	at sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:213)
	at sun.nio.ch.KQueuePort$EventHandlerTask.run(KQueuePort.java:301)
	at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

I have not seen this error when using the synchronous driver. It only showed up when using the async driver.



 Comments   
Comment by Steve Hummingbird [ 14/Oct/17 ]

I can confirm. Haven’t seen that issue for a while now. Thanks.

Comment by Ross Lawley [ 29/Sep/17 ]

I was unable to replicate the error with the 3.0.0 driver, so this looks like it was fixed sometime before 3.0.0 was released. (I had to update the package locations etc when testing).

I also tried using: https://github.com/vert-x3/vertx-gradle-starter and witnessed it redeploying as expected on Vert.x 3.0.

Comment by Steve Hummingbird [ 19/Jun/14 ]

Thanks Ross for providing a workaround. This makes development fluent again Vert.x should already have a dependency to netty, so changing the command seems to be sufficient.

Comment by Ross Lawley [ 19/Jun/14 ]

Thanks Steve Hummingbird I'm looking into this now. We are hitting an issue with NIO that I'm investigating. If you use netty - by adding netty to the compile in your example and then run:

./gradlew -Dorg.mongodb.async.type=netty runMod -i 

it reloads without issue.

Comment by Steve Hummingbird [ 19/Jun/14 ]

Also adding a minimal example in Java 8, which does nothing except loading the driver and connecting the a database. Steps to reproduce are similar, but needs a compile within the IDE first.

Attempting to create module link for module com.mycompany~my-module~1.0.0-final
Succeeded in creating module link
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "args" on "task ':runMod'", value: "[runmod, com.mycompany...".
creating mongoClient...
Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN}
Succeeded in deploying module
Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[2, 4, 8]}, minWireVersion=0, maxWireVersion=0, maxDocumentSize=16777216, maxMessageSize=48000000, maxWriteBatchSize=512, averagePingTimeNanos=171000}
Module com.mycompany~my-module~1.0.0-final has changed, reloading it.
closing mongoClient...
creating mongoClient....
Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN}
Exception in thread "Thread-7" java.lang.IllegalAccessError: tried to access class org.mongodb.connection.AsynchronousSocketChannelStream$AsyncWritableByteChannelAdapter$1$1 from class org.mongodb.connection.AsynchronousSocketChannelStream$AsyncWritableByteChannelAdapter$1
	at org.mongodb.connection.AsynchronousSocketChannelStream$AsyncWritableByteChannelAdapter$1.completed(AsynchronousSocketChannelStream.java:183)
	at org.mongodb.connection.AsynchronousSocketChannelStream$AsyncWritableByteChannelAdapter$1.completed(AsynchronousSocketChannelStream.java:180)
	at org.mongodb.connection.AsynchronousSocketChannelStream$2.completed(AsynchronousSocketChannelStream.java:140)
	at org.mongodb.connection.AsynchronousSocketChannelStream$2.completed(AsynchronousSocketChannelStream.java:137)
	at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126)
	at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:278)
	at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:198)
	at sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:213)
	at sun.nio.ch.KQueuePort$EventHandlerTask.run(KQueuePort.java:301)
	at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Comment by Steve Hummingbird [ 17/Jun/14 ]

I created a small example of how I am using the driver. To reproduce:

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