Skip to content

Commit 4193602

Browse files
committed
Checking for null cursorCleaningService in Mongo.close()
JAVA-1798
1 parent 4ee59c0 commit 4193602

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

driver/src/main/com/mongodb/Mongo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ public void dropDatabase(final String dbName) {
469469
*/
470470
public void close() {
471471
cluster.close();
472-
cursorCleaningService.shutdownNow();
472+
if (cursorCleaningService != null) {
473+
cursorCleaningService.shutdownNow();
474+
}
473475
}
474476

475477
/**

driver/src/test/unit/com/mongodb/MongoConstructorsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ public void shouldSaveDefaultWriteConcern() throws UnknownHostException {
114114
}
115115
}
116116

117+
@Test
118+
public void shouldCloseWithoutExceptionWhenCursorFinalizerIsDisabled() {
119+
Mongo mongo = new MongoClient(new ServerAddress(), MongoClientOptions.builder().cursorFinalizerEnabled(false).build());
120+
mongo.close();
121+
}
122+
117123
@Test
118124
@SuppressWarnings("deprecation") // This is for testing the old API, so it will use deprecated methods
119125
public void shouldGetDB() throws UnknownHostException {

0 commit comments

Comments
 (0)