[JAVA-2724] Fix issues reported by Coverity Created: 02/Jan/18  Updated: 28/Oct/23  Resolved: 26/Apr/18

Status: Closed
Project: Java Driver
Component/s: Internal
Affects Version/s: None
Fix Version/s: 3.7.0

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

There issues were reported by a Coverity scan of the driver code:

16186 Dereference null return value
If the function actually returns a null value, a NullPointerException will be thrown.
  In com.​mongodb.​ReplicaSetStatus.​isMaster(com.​mongodb.​ServerAddress): Return value of function which returns null is dereferenced without checking (CWE-476)
 
 
99028 Missing call to superclass
Whatever action the superclass method implements will not occur, if the superclass call is actually required.
   In com.​mongodb.​binding.​SingleServerBinding$SingleServerBindingConnectionSource.​release(): Overrider does not call the superclass method, even though most other overriders do (CWE-573)
 
 
99031 Unguarded read
The value of the shared data will be determined by the interleaving of thread execution.
   In com.​mongodb.​async.​client.​AbstractSubscription.​getRequested(): Thread shared data is accessed without holding an appropriate lock, possibly causing a race condition (CWE-366)
 
 
99034 Using invalid iterator
A concurrent modification exception may result, the container may be corrupted, or the iterator may return incorrect data.
   In com.​mongodb.​connection.​MultiServerCluster.​removeExtraHosts(com.​mongodb.​connection.​ServerDescription): An iterator is being used after the source container of the iterator is modified (CWE-573)
 
 
99036 Dereference null return value
If the function actually returns a null value, a NullPointerException will be thrown.
   In com.​mongodb.​connection.​SaslAuthenticator$1.​run(): Return value of function which returns null is dereferenced without checking (CWE-476)
 
 
99041 Resource leak
The system resource will not be reclaimed and reused, reducing the future availability of the resource.
   In com.​mongodb.​connection.​ReplyMessage.​ReplyMessage(com.​mongodb.​connection.​ResponseBuffers, org.​bson.​codecs.​Decoder, long): Leak of a system resource (CWE-404)
 
 
99042 Volatile not atomically updated
Some updates to the volatile variable may be lost, depending on the interleaving of thread execution.
   In com.​mongodb.​operation.​AsyncQueryBatchCursor.​AsyncQueryBatchCursor(com.​mongodb.​connection.​QueryResult, int, int, long, org.​bson.​codecs.​Decoder, com.​mongodb.​binding.​AsyncConnectionSource, com.​mongodb.​connection.​AsyncConnection): A volatile variable is updated in a non-atomic manner (CWE-366)
 
 
99044 FS: Format string problem
   In DocTaglet.​toString(com.​sun.​javadoc.​Tag[]): This format string include a newline character (\n). (From FindBugs™ description)
 
 
102372 Resource leak
The system resource will not be reclaimed and reused, reducing the future availability of the resource.
   In com.​mongodb.​internal.​dns.​DnsResolver.​resolveAdditionalQueryParametersFromTxtRecords(java.​lang.​String): Leak of a system resource (CWE-404)
 
 
102384 Dereference before null check
There may be a null pointer exception, or else the comparison against null is unnecessary.
   In com.​mongodb.​connection.​CommandMessage.​addDocumentWithPayload(org.​bson.​io.​BsonOutput, int): All paths that lead to this null pointer comparison already dereference the pointer earlier (CWE-476)
 
 
102385 Dereference null return value
If the function actually returns a null value, a NullPointerException will be thrown.
   In com.​mongodb.​connection.​BaseCluster.​createIncompatibleException(com.​mongodb.​connection.​ClusterDescription): Return value of function which returns null is dereferenced without checking (CWE-476)



 Comments   
Comment by Githook User [ 30/Apr/18 ]

Author:

{'email': 'fares.hassak@gmail.com', 'username': 'fhassak', 'name': 'Farès Hassak'}

Message: JAVA-2724 : Remove %n in String.format call in DocTaglet
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/30d02a9313498b06f9e69166600d993154a70f15

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Modify addressToServerTupleMap in MultiServerCluster via the Iterator instead of Map#remove
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/01a87501bc727587ee6e0b73f0b1d2e20241b4bc

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Synchronize getters for AbstractSubscription fields that require it
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/16dc469471af05ecf16573bc58dffd326d5cd9d8

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Call super.release() in SingleServerBindingConnectionSource#release.
Only retain the SingleServerBinding in the SingleServerBindingConnectionSource constructing
and release it when the reference count on the connection source drops to zero.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b873c3801e5d270c4a9bcfc09ad942c2f265418b

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Check for null primary in ReplicaSetStatus#isMaster to avoid NPE
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/db82049a9cbe0f3755586b3470712a13bed124aa

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Throw MongoSecurityException if SaslClient is null
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/e9e988d42bd4272daae46d9d7a0a496f4ee3d0ab

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Close ByteBufferBsonInput in ReplyMessage constructor

This isn't strictly necessary since we don't want the underlying ByteBuf to be close,
but it clarifies the purpose by duplicating the ByteBuf and then closing the
ByteBufferBsonInput.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/6167a4ff09b47d7407b7d17b27ce899faeec88bf

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Replace \n with %n in String.format call in DocTaglet
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/8331079d529ea3df6b4f2f0d9c59d46d82965eb4

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Replace incorrect use of volatile integer with AtomicInteger in AsyncQueryBatchCursor
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/f6e82d2313ea268c31c0b6edfbae41d696a3887f

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Remove unnecessary null check in CommandMessage#addDocumentWithPayload
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b93b8fb8ab9a15438faf5cb90f218589c8fd6b0d

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Return MongoIncompatibleDriverException instead of throwing it in BaseCluster#createIncompatibleException
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/d3bc618fa7f2683ee52ddf009e7f96e013c443de

Comment by Githook User [ 09/Jan/18 ]

Author:

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

Message: JAVA-2724: Close InitialDirContext in the DnsResolver
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/5aa4c29f77fc1c5668a36e1a068c4af572642607

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