|
56 | 56 | import static com.mongodb.internal.connection.OidcAuthenticator.OidcValidator.validateCreateOidcCredential; |
57 | 57 | import static java.lang.String.format; |
58 | 58 | import static java.util.Arrays.asList; |
| 59 | +import static java.util.Collections.emptyList; |
59 | 60 | import static java.util.Collections.singletonList; |
60 | 61 | import static java.util.Collections.unmodifiableList; |
61 | 62 |
|
@@ -1260,20 +1261,24 @@ private void validateProxyParameters(final Map<String, List<String>> optionsMap) |
1260 | 1261 | "Both proxyUsername and proxyPassword must be set together. They cannot be set individually"); |
1261 | 1262 | } |
1262 | 1263 |
|
1263 | | - if (proxyHost != null && optionsMap.get("proxyhost").size() > 1) { |
| 1264 | + if (containsDuplicatedOptions("proxyhost", optionsMap)) { |
1264 | 1265 | throw new IllegalArgumentException("Duplicated values for proxyHost: " + optionsMap.get("proxyhost")); |
1265 | 1266 | } |
1266 | | - if (proxyPort != null && optionsMap.get("proxyport").size() > 1) { |
| 1267 | + if (containsDuplicatedOptions("proxyport", optionsMap)) { |
1267 | 1268 | throw new IllegalArgumentException("Duplicated values for proxyPort: " + optionsMap.get("proxyport")); |
1268 | 1269 | } |
1269 | | - if (proxyPassword != null && optionsMap.get("proxypassword").size() > 1) { |
| 1270 | + if (containsDuplicatedOptions("proxypassword", optionsMap)) { |
1270 | 1271 | throw new IllegalArgumentException("Duplicated values for proxyPassword: " + optionsMap.get("proxypassword")); |
1271 | 1272 | } |
1272 | | - if (proxyUsername != null && optionsMap.get("proxyusername").size() > 1) { |
| 1273 | + if (containsDuplicatedOptions("proxyusername", optionsMap)) { |
1273 | 1274 | throw new IllegalArgumentException("Duplicated values for proxyUsername: " + optionsMap.get("proxyusername")); |
1274 | 1275 | } |
1275 | 1276 | } |
1276 | 1277 |
|
| 1278 | + private static boolean containsDuplicatedOptions(final String optionName, final Map<String, List<String>> optionsMap) { |
| 1279 | + return optionsMap.getOrDefault(optionName, emptyList()).size() > 1; |
| 1280 | + } |
| 1281 | + |
1277 | 1282 | private int countOccurrences(final String haystack, final String needle) { |
1278 | 1283 | return haystack.length() - haystack.replace(needle, "").length(); |
1279 | 1284 | } |
|
0 commit comments