From 112b707b67c1b5926997ab114415fb29b4190764 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 18 Jan 2016 16:06:38 +0000 Subject: [PATCH] Ensure that MongoClient is not created with a null credentials list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mongo’s 2.x driver allowed the credentials list to be null, however the 3.x driver requires an empty list instead. The behaviour of the 2.x driver is the same whether the client is created with a null credential list or an empty credential list. This commit aligns with the requirements of the 3.x driver by ensuring that we never pass in a null credential list when creating the client. Closes gh-4076 --- .../boot/autoconfigure/mongo/MongoProperties.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java index 82303f721b..ae3f8b643c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.mongo; import java.net.UnknownHostException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -213,12 +214,12 @@ public class MongoProperties { if (options == null) { options = MongoClientOptions.builder().build(); } - List credentials = null; + List credentials = new ArrayList(); if (hasCustomCredentials()) { String database = this.authenticationDatabase == null ? getMongoClientDatabase() : this.authenticationDatabase; - credentials = Arrays.asList(MongoCredential - .createCredential(this.username, database, this.password)); + credentials.add(MongoCredential.createCredential(this.username, + database, this.password)); } String host = this.host == null ? "localhost" : this.host; int port = determinePort(environment);