[JAVA-4505] org.mongodb.driver-core-4.5.0 requires javax.annotation.meta but it could not be found Created: 19/Feb/22  Updated: 28/Oct/23  Resolved: 17/Mar/22

Status: Closed
Project: Java Driver
Component/s: Packaging
Affects Version/s: 4.5.0
Fix Version/s: 4.5.1

Type: Bug Priority: Minor - P4
Reporter: Donald Duck Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

When I upgrade my OSGi target platform so it uses the 4.5.0 Java driver JARs, I get
[ERROR] Missing requirement: org.mongodb.driver-core 4.5.0 requires 'java.package; javax.annotation.meta 0.0.0' but it could not be found in my Tycho build. I'm on Java 8. It reminds me of JAVA-4399 where a jdk.net dependency killed the OSGi / Tycho build. Is it possible that this dependency shouldn't exist?



 Comments   
Comment by Jeffrey Yemin [ 23/Mar/22 ]

FYI, 4.5.1 has been released with a fix for this issue.

Comment by Donald Duck [ 17/Mar/22 ]

Thx

Comment by Githook User [ 17/Mar/22 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Exclude javax.annotation.* from OSGi imports (#895)

JAVA-4505
Branch: 4.5.x
https://github.com/mongodb/mongo-java-driver/commit/bcdb1e553d6d4cbeb149bcfb5232295b6fed58ae

Comment by Githook User [ 17/Mar/22 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Exclude javax.annotation.* from OSGi imports (#895)

JAVA-4505
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/1ca647799e036cd0c7471b7eb16a756ba54f8f32

Comment by Donald Duck [ 08/Mar/22 ]

java.lang.NullPointerException: while trying to invoke the method java.lang.Object.getClass() of a null object loaded from local variable 'value'
at org.bson.codecs.BsonArrayCodec.encode(BsonArrayCodec.java:81)
at org.bson.codecs.BsonArrayCodec.encode(BsonArrayCodec.java:37)
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:210)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:168)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:44)
at org.bson.internal.LazyCodec.encode(LazyCodec.java:38)
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:210)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:168)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:44)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.internal.connection.SplittablePayload$WriteRequestEncoder.encode(SplittablePayload.java:200)
at com.mongodb.internal.connection.SplittablePayload$WriteRequestEncoder.encode(SplittablePayload.java:187)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.internal.connection.BsonWriterHelper.writeDocument(BsonWriterHelper.java:77)
at com.mongodb.internal.connection.BsonWriterHelper.writePayload(BsonWriterHelper.java:59)
at com.mongodb.internal.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:168)
at com.mongodb.internal.connection.RequestMessage.encode(RequestMessage.java:138)
at com.mongodb.internal.connection.CommandMessage.encode(CommandMessage.java:62)
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:326)
at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:116)
at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:643)
at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:71)
at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:240)
at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:226)
at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:126)
at com.mongodb.internal.connection.DefaultServer$OperationCountTrackingConnection.command(DefaultServer.java:354)
at com.mongodb.internal.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:477)
at com.mongodb.internal.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:339)
at com.mongodb.internal.operation.MixedBulkWriteOperation.lambda$execute$2(MixedBulkWriteOperation.java:260)
at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$2(OperationHelper.java:575)
at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:600)
at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$3(OperationHelper.java:574)
at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:600)
at com.mongodb.internal.operation.OperationHelper.withSourceAndConnection(OperationHelper.java:573)
at com.mongodb.internal.operation.MixedBulkWriteOperation.lambda$execute$3(MixedBulkWriteOperation.java:232)
at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:65)
at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:268)
at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:84)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:212)
at com.mongodb.client.internal.MongoCollectionImpl.executeInsertMany(MongoCollectionImpl.java:499)
at com.mongodb.client.internal.MongoCollectionImpl.insertMany(MongoCollectionImpl.java:481)
at com.mongodb.client.internal.MongoCollectionImpl.insertMany(MongoCollectionImpl.java:476)
...

The "value" parameter in the DocumentCodec.writeValue(BdonWriter, EncoderContext, Object) method is:
BsonArray{values=[null, BsonDouble

{value=12.0}

]}
and it is the null value for index 0 that is offending. BsonArrayCodec.encode then fails with the value.getClass() call in line 81.

Comment by Jeffrey Yemin [ 07/Mar/22 ]

Thanks for the update. Would you mind posting the NPE that you encountered? It's not ringing any bells.

Comment by Donald Duck [ 07/Mar/22 ]

Yes, adding the jsr305 jar to our target platform allows us to proceed for now. As usual for many JARs, that JAR from Maven central needs manifest patching to make it into an OSGi bundle. Then, after being able to build again a few tests failed, based on BsonArray instances with null value which seem to have passed through storing without problems in the old version of the driver but now cause an NPE, but that was an easy fix, and I saw that at least the BsonArray constructor with a values array has ever since demanded non-null values only. (Nota bene: throwing an NPE in the BsonArray.add(BsonValue) method would help catch the root cause of such problems with more confidence, I think.)
Thanks for your support.

Comment by Jeffrey Yemin [ 07/Mar/22 ]

mongo@homemp3.dyndns.org were you able to work around this or are you blocked from upgrading?

Comment by Jeffrey Yemin [ 28/Feb/22 ]

Ah, that makes more sense now. I looked at the 4.3.1 MANIFEST.MF and javax.annotation doesn't appear at all, but in 4.4.0 it does. Looking at the changes in 4.4.0, JAVA-4381 seems like the most likely thing that changed the manifest.

As a workaround, can you take a dependency on com.google.code.findbugs:jsr305:1.3.9 while we investigate a fix?

Comment by Donald Duck [ 28/Feb/22 ]

Sorry, I double-checked, and so far we are using 4.3.1

Comment by Donald Duck [ 28/Feb/22 ]

From 4.4

Comment by Jeffrey Yemin [ 28/Feb/22 ]

The driver takes a compile-only dependency on com.google.code.findbugs:jsr305:1.3.9, which is where the driver finds the javax.annotation.meta classes. I'm not sure why this results an an entry in Import-Package in the manifest, but it's been there for a while. What driver release are you upgrading from?

Comment by Donald Duck [ 28/Feb/22 ]

I can't get a Tycho build running with a dependency to this Jar with Java8 because the javax.annotation.meta package cannot be resolved. It is a mandatory dependency of the mongodb jar and I wonder where to satisfy it from under Java8.

Comment by Jeffrey Yemin [ 28/Feb/22 ]

mongo@homemp3.dyndns.org, the dependency still exists, as a result of this commit. And I still see it listed in the 4.5 manifest for driver-core.

So I'm not sure what the issue is yet. Do you see any issues with the manifest?

Comment by Esha Bhargava [ 22/Feb/22 ]

mongo@homemp3.dyndns.org Thank you for reporting this issue! We'll look into it and get back to you soon.

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