18
18
19
19
import com .mongodb .diagnostics .logging .Logger ;
20
20
import com .mongodb .diagnostics .logging .Loggers ;
21
+ import com .mongodb .lang .Nullable ;
21
22
22
23
import java .io .UnsupportedEncodingException ;
23
24
import java .net .URLDecoder ;
@@ -510,7 +511,7 @@ private List<MongoCompressor> createCompressors(final Map<String, List<String>>
510
511
return buildCompressors (compressors , zlibCompressionLevel );
511
512
}
512
513
513
- private List <MongoCompressor > buildCompressors (final String compressors , final Integer zlibCompressionLevel ) {
514
+ private List <MongoCompressor > buildCompressors (final String compressors , @ Nullable final Integer zlibCompressionLevel ) {
514
515
List <MongoCompressor > compressorsList = new ArrayList <MongoCompressor >();
515
516
516
517
for (String cur : compressors .split ("," )) {
@@ -530,6 +531,7 @@ private List<MongoCompressor> buildCompressors(final String compressors, final I
530
531
return unmodifiableList (compressorsList );
531
532
}
532
533
534
+ @ Nullable
533
535
private WriteConcern createWriteConcern (final Map <String , List <String >> optionsMap ) {
534
536
Boolean safe = null ;
535
537
String w = null ;
@@ -558,6 +560,7 @@ private WriteConcern createWriteConcern(final Map<String, List<String>> optionsM
558
560
return buildWriteConcern (safe , w , wTimeout , fsync , journal );
559
561
}
560
562
563
+ @ Nullable
561
564
private ReadPreference createReadPreference (final Map <String , List <String >> optionsMap ) {
562
565
String readPreferenceType = null ;
563
566
List <TagSet > tagSetList = new ArrayList <TagSet >();
@@ -583,8 +586,9 @@ private ReadPreference createReadPreference(final Map<String, List<String>> opti
583
586
return buildReadPreference (readPreferenceType , tagSetList , maxStalenessSeconds );
584
587
}
585
588
586
- private MongoCredential createCredentials (final Map <String , List <String >> optionsMap , final String userName ,
587
- final char [] password ) {
589
+ @ Nullable
590
+ private MongoCredential createCredentials (final Map <String , List <String >> optionsMap , @ Nullable final String userName ,
591
+ @ Nullable final char [] password ) {
588
592
AuthenticationMechanism mechanism = null ;
589
593
String authSource = (database == null ) ? "admin" : database ;
590
594
String gssapiServiceName = null ;
@@ -637,8 +641,8 @@ private MongoCredential createCredentials(final Map<String, List<String>> option
637
641
638
642
@ SuppressWarnings ("deprecation" )
639
643
private MongoCredential createMongoCredentialWithMechanism (final AuthenticationMechanism mechanism , final String userName ,
640
- final char [] password , final String authSource ,
641
- final String gssapiServiceName ) {
644
+ @ Nullable final char [] password , final String authSource ,
645
+ @ Nullable final String gssapiServiceName ) {
642
646
MongoCredential credential ;
643
647
switch (mechanism ) {
644
648
case GSSAPI :
@@ -667,6 +671,7 @@ private MongoCredential createMongoCredentialWithMechanism(final AuthenticationM
667
671
return credential ;
668
672
}
669
673
674
+ @ Nullable
670
675
private String getLastValue (final Map <String , List <String >> optionsMap , final String key ) {
671
676
List <String > valueList = optionsMap .get (key );
672
677
if (valueList == null ) {
@@ -709,8 +714,9 @@ private Map<String, List<String>> parseOptions(final String optionsPart) {
709
714
}
710
715
}
711
716
// handle legacy slaveok settings
712
- if (optionsMap .containsKey ("slaveok" ) && !optionsMap .containsKey ("readpreference" )) {
713
- String readPreference = parseBoolean (getLastValue (optionsMap , "slaveok" ), "slaveok" )
717
+ String slaveok = getLastValue (optionsMap , "slaveok" );
718
+ if (slaveok != null && !optionsMap .containsKey ("readpreference" )) {
719
+ String readPreference = parseBoolean (slaveok , "slaveok" )
714
720
? "secondaryPreferred" : "primary" ;
715
721
optionsMap .put ("readpreference" , singletonList (readPreference ));
716
722
if (LOGGER .isWarnEnabled ()) {
@@ -728,7 +734,8 @@ private Map<String, List<String>> parseOptions(final String optionsPart) {
728
734
return optionsMap ;
729
735
}
730
736
731
- private ReadPreference buildReadPreference (final String readPreferenceType ,
737
+ @ Nullable
738
+ private ReadPreference buildReadPreference (@ Nullable final String readPreferenceType ,
732
739
final List <TagSet > tagSetList , final long maxStalenessSeconds ) {
733
740
if (readPreferenceType != null ) {
734
741
if (tagSetList .isEmpty () && maxStalenessSeconds == -1 ) {
@@ -746,8 +753,10 @@ private ReadPreference buildReadPreference(final String readPreferenceType,
746
753
}
747
754
748
755
@ SuppressWarnings ("deprecation" )
749
- private WriteConcern buildWriteConcern (final Boolean safe , final String w ,
750
- final Integer wTimeout , final Boolean fsync , final Boolean journal ) {
756
+ @ Nullable
757
+ private WriteConcern buildWriteConcern (@ Nullable final Boolean safe , @ Nullable final String w ,
758
+ @ Nullable final Integer wTimeout , @ Nullable final Boolean fsync ,
759
+ @ Nullable final Boolean journal ) {
751
760
WriteConcern retVal = null ;
752
761
if (w != null || wTimeout != null || fsync != null || journal != null ) {
753
762
if (w == null ) {
@@ -904,6 +913,7 @@ private String urldecode(final String input, final boolean password) {
904
913
*
905
914
* @return the username
906
915
*/
916
+ @ Nullable
907
917
public String getUsername () {
908
918
return credential != null ? credential .getUserName () : null ;
909
919
}
@@ -913,6 +923,7 @@ public String getUsername() {
913
923
*
914
924
* @return the password
915
925
*/
926
+ @ Nullable
916
927
public char [] getPassword () {
917
928
return credential != null ? credential .getPassword () : null ;
918
929
}
@@ -931,6 +942,7 @@ public List<String> getHosts() {
931
942
*
932
943
* @return the database name
933
944
*/
945
+ @ Nullable
934
946
public String getDatabase () {
935
947
return database ;
936
948
}
@@ -941,6 +953,7 @@ public String getDatabase() {
941
953
*
942
954
* @return the collection name
943
955
*/
956
+ @ Nullable
944
957
public String getCollection () {
945
958
return collection ;
946
959
}
@@ -984,6 +997,7 @@ public List<MongoCredential> getCredentialList() {
984
997
* @return the credentials in an immutable list
985
998
* @since 3.6
986
999
*/
1000
+ @ Nullable
987
1001
public MongoCredential getCredential () {
988
1002
return credential ;
989
1003
}
@@ -992,6 +1006,7 @@ public MongoCredential getCredential() {
992
1006
* Gets the read preference specified in the connection string.
993
1007
* @return the read preference
994
1008
*/
1009
+ @ Nullable
995
1010
public ReadPreference getReadPreference () {
996
1011
return readPreference ;
997
1012
}
@@ -1000,6 +1015,7 @@ public ReadPreference getReadPreference() {
1000
1015
* Gets the read concern specified in the connection string.
1001
1016
* @return the read concern
1002
1017
*/
1018
+ @ Nullable
1003
1019
public ReadConcern getReadConcern () {
1004
1020
return readConcern ;
1005
1021
}
@@ -1008,6 +1024,7 @@ public ReadConcern getReadConcern() {
1008
1024
* Gets the write concern specified in the connection string.
1009
1025
* @return the write concern
1010
1026
*/
1027
+ @ Nullable
1011
1028
public WriteConcern getWriteConcern () {
1012
1029
return writeConcern ;
1013
1030
}
@@ -1027,6 +1044,7 @@ public boolean getRetryWrites() {
1027
1044
* Gets the minimum connection pool size specified in the connection string.
1028
1045
* @return the minimum connection pool size
1029
1046
*/
1047
+ @ Nullable
1030
1048
public Integer getMinConnectionPoolSize () {
1031
1049
return minConnectionPoolSize ;
1032
1050
}
@@ -1035,6 +1053,7 @@ public Integer getMinConnectionPoolSize() {
1035
1053
* Gets the maximum connection pool size specified in the connection string.
1036
1054
* @return the maximum connection pool size
1037
1055
*/
1056
+ @ Nullable
1038
1057
public Integer getMaxConnectionPoolSize () {
1039
1058
return maxConnectionPoolSize ;
1040
1059
}
@@ -1043,6 +1062,7 @@ public Integer getMaxConnectionPoolSize() {
1043
1062
* Gets the multiplier for the number of threads allowed to block waiting for a connection specified in the connection string.
1044
1063
* @return the multiplier for the number of threads allowed to block waiting for a connection
1045
1064
*/
1065
+ @ Nullable
1046
1066
public Integer getThreadsAllowedToBlockForConnectionMultiplier () {
1047
1067
return threadsAllowedToBlockForConnectionMultiplier ;
1048
1068
}
@@ -1051,6 +1071,7 @@ public Integer getThreadsAllowedToBlockForConnectionMultiplier() {
1051
1071
* Gets the maximum wait time of a thread waiting for a connection specified in the connection string.
1052
1072
* @return the maximum wait time of a thread waiting for a connection
1053
1073
*/
1074
+ @ Nullable
1054
1075
public Integer getMaxWaitTime () {
1055
1076
return maxWaitTime ;
1056
1077
}
@@ -1059,6 +1080,7 @@ public Integer getMaxWaitTime() {
1059
1080
* Gets the maximum connection idle time specified in the connection string.
1060
1081
* @return the maximum connection idle time
1061
1082
*/
1083
+ @ Nullable
1062
1084
public Integer getMaxConnectionIdleTime () {
1063
1085
return maxConnectionIdleTime ;
1064
1086
}
@@ -1067,6 +1089,7 @@ public Integer getMaxConnectionIdleTime() {
1067
1089
* Gets the maximum connection life time specified in the connection string.
1068
1090
* @return the maximum connection life time
1069
1091
*/
1092
+ @ Nullable
1070
1093
public Integer getMaxConnectionLifeTime () {
1071
1094
return maxConnectionLifeTime ;
1072
1095
}
@@ -1075,6 +1098,7 @@ public Integer getMaxConnectionLifeTime() {
1075
1098
* Gets the socket connect timeout specified in the connection string.
1076
1099
* @return the socket connect timeout
1077
1100
*/
1101
+ @ Nullable
1078
1102
public Integer getConnectTimeout () {
1079
1103
return connectTimeout ;
1080
1104
}
@@ -1083,6 +1107,7 @@ public Integer getConnectTimeout() {
1083
1107
* Gets the socket timeout specified in the connection string.
1084
1108
* @return the socket timeout
1085
1109
*/
1110
+ @ Nullable
1086
1111
public Integer getSocketTimeout () {
1087
1112
return socketTimeout ;
1088
1113
}
@@ -1091,6 +1116,7 @@ public Integer getSocketTimeout() {
1091
1116
* Gets the SSL enabled value specified in the connection string.
1092
1117
* @return the SSL enabled value
1093
1118
*/
1119
+ @ Nullable
1094
1120
public Boolean getSslEnabled () {
1095
1121
return sslEnabled ;
1096
1122
}
@@ -1100,6 +1126,7 @@ public Boolean getSslEnabled() {
1100
1126
* @return the stream type value
1101
1127
* @since 3.3
1102
1128
*/
1129
+ @ Nullable
1103
1130
public String getStreamType () {
1104
1131
return streamType ;
1105
1132
}
@@ -1110,6 +1137,7 @@ public String getStreamType() {
1110
1137
* @return the SSL invalidHostnameAllowed value
1111
1138
* @since 3.3
1112
1139
*/
1140
+ @ Nullable
1113
1141
public Boolean getSslInvalidHostnameAllowed () {
1114
1142
return sslInvalidHostnameAllowed ;
1115
1143
}
@@ -1118,6 +1146,7 @@ public Boolean getSslInvalidHostnameAllowed() {
1118
1146
* Gets the required replica set name specified in the connection string.
1119
1147
* @return the required replica set name
1120
1148
*/
1149
+ @ Nullable
1121
1150
public String getRequiredReplicaSetName () {
1122
1151
return requiredReplicaSetName ;
1123
1152
}
@@ -1127,6 +1156,7 @@ public String getRequiredReplicaSetName() {
1127
1156
* @return the server selection timeout (in milliseconds), or null if unset
1128
1157
* @since 3.3
1129
1158
*/
1159
+ @ Nullable
1130
1160
public Integer getServerSelectionTimeout () {
1131
1161
return serverSelectionTimeout ;
1132
1162
}
@@ -1136,6 +1166,7 @@ public Integer getServerSelectionTimeout() {
1136
1166
* @return the local threshold (in milliseconds), or null if unset
1137
1167
* since 3.3
1138
1168
*/
1169
+ @ Nullable
1139
1170
public Integer getLocalThreshold () {
1140
1171
return localThreshold ;
1141
1172
}
@@ -1145,6 +1176,7 @@ public Integer getLocalThreshold() {
1145
1176
* @return the heartbeat frequency (in milliseconds), or null if unset
1146
1177
* since 3.3
1147
1178
*/
1179
+ @ Nullable
1148
1180
public Integer getHeartbeatFrequency () {
1149
1181
return heartbeatFrequency ;
1150
1182
}
@@ -1159,6 +1191,7 @@ public Integer getHeartbeatFrequency() {
1159
1191
* @since 3.4
1160
1192
* @mongodb.server.release 3.4
1161
1193
*/
1194
+ @ Nullable
1162
1195
public String getApplicationName () {
1163
1196
return applicationName ;
1164
1197
}
0 commit comments