@@ -806,9 +806,14 @@ static Filter createEqualityFilter(@NotNull final String attributeName,
806
806
* @param attributeName The attribute name for this substring filter. It
807
807
* must not be {@code null}.
808
808
* @param subInitial The subInitial component for this substring filter.
809
+ * It may be {@code null} if there is no subInitial
810
+ * component, but it must not be empty.
809
811
* @param subAny The set of subAny components for this substring
810
- * filter.
812
+ * filter. It may be {@code null} or empty if there
813
+ * are no subAny components.
811
814
* @param subFinal The subFinal component for this substring filter.
815
+ * It may be {@code null} if there is no subFinal
816
+ * component, but it must not be empty.
812
817
*
813
818
* @return The created substring search filter.
814
819
*/
@@ -835,9 +840,14 @@ public static Filter substring(@NotNull final String attributeName,
835
840
* @param attributeName The attribute name for this substring filter. It
836
841
* must not be {@code null}.
837
842
* @param subInitial The subInitial component for this substring filter.
843
+ * It may be {@code null} if there is no subInitial
844
+ * component, but it must not be empty.
838
845
* @param subAny The set of subAny components for this substring
839
- * filter.
846
+ * filter. It may be {@code null} or empty if there
847
+ * are no subAny components.
840
848
* @param subFinal The subFinal component for this substring filter.
849
+ * It may be {@code null} if there is no subFinal
850
+ * component, but it must not be empty.
841
851
*
842
852
* @return The created substring search filter.
843
853
*/
@@ -860,9 +870,14 @@ public static Filter substring(@NotNull final String attributeName,
860
870
* @param attributeName The attribute name for this substring filter. It
861
871
* must not be {@code null}.
862
872
* @param subInitial The subInitial component for this substring filter.
873
+ * It may be {@code null} if there is no subInitial
874
+ * component, but it must not be empty.
863
875
* @param subAny The set of subAny components for this substring
864
- * filter.
876
+ * filter. It may be {@code null} or empty if there
877
+ * are no subAny components.
865
878
* @param subFinal The subFinal component for this substring filter.
879
+ * It may be {@code null} if there is no subFinal
880
+ * component, but it must not be empty.
866
881
*
867
882
* @return The created substring search filter.
868
883
*/
@@ -874,12 +889,16 @@ public static Filter createSubstringFilter(
874
889
@ Nullable final String subFinal )
875
890
{
876
891
Validator .ensureNotNull (attributeName );
877
- Validator .ensureTrue ((subInitial != null ) ||
878
- ((subAny != null ) && (subAny .length > 0 )) ||
879
- (subFinal != null ));
892
+ Validator .ensureTrue (
893
+ (((subInitial != null ) && (subInitial .length () > 0 )) ||
894
+ ((subAny != null ) && (subAny .length > 0 ) &&
895
+ (subAny [0 ].length () > 0 )) ||
896
+ ((subFinal != null ) && (subFinal .length () > 0 ))),
897
+ "At least one substring filter component must be non-null and " +
898
+ "non-empty" );
880
899
881
900
final ASN1OctetString subInitialOS ;
882
- if (subInitial == null )
901
+ if (( subInitial == null ) || subInitial . isEmpty () )
883
902
{
884
903
subInitialOS = null ;
885
904
}
@@ -895,15 +914,34 @@ public static Filter createSubstringFilter(
895
914
}
896
915
else
897
916
{
898
- subAnyArray = new ASN1OctetString [subAny .length ];
899
- for (int i =0 ; i < subAny .length ; i ++)
917
+ if (subAny .length == 1 )
918
+ {
919
+ if (subAny [0 ].length () == 0 )
920
+ {
921
+ subAnyArray = NO_SUB_ANY ;
922
+ }
923
+ else
924
+ {
925
+ subAnyArray = new ASN1OctetString []
926
+ {
927
+ new ASN1OctetString (subAny [0 ])
928
+ };
929
+ }
930
+ }
931
+ else
900
932
{
901
- subAnyArray [i ] = new ASN1OctetString (subAny [i ]);
933
+ subAnyArray = new ASN1OctetString [subAny .length ];
934
+ for (int i =0 ; i < subAny .length ; i ++)
935
+ {
936
+ Validator .ensureFalse (subAny [i ].isEmpty (),
937
+ "Individual substring filter components must not be empty" );
938
+ subAnyArray [i ] = new ASN1OctetString (subAny [i ]);
939
+ }
902
940
}
903
941
}
904
942
905
943
final ASN1OctetString subFinalOS ;
906
- if (subFinal == null )
944
+ if (( subFinal == null ) || subFinal . isEmpty () )
907
945
{
908
946
subFinalOS = null ;
909
947
}
@@ -927,9 +965,14 @@ public static Filter createSubstringFilter(
927
965
* @param attributeName The attribute name for this substring filter. It
928
966
* must not be {@code null}.
929
967
* @param subInitial The subInitial component for this substring filter.
968
+ * It may be {@code null} if there is no subInitial
969
+ * component, but it must not be empty.
930
970
* @param subAny The set of subAny components for this substring
931
- * filter.
971
+ * filter. It may be {@code null} or empty if there
972
+ * are no subAny components.
932
973
* @param subFinal The subFinal component for this substring filter.
974
+ * It may be {@code null} if there is no subFinal
975
+ * component, but it must not be empty.
933
976
*
934
977
* @return The created substring search filter.
935
978
*/
@@ -941,12 +984,16 @@ public static Filter createSubstringFilter(
941
984
@ Nullable final byte [] subFinal )
942
985
{
943
986
Validator .ensureNotNull (attributeName );
944
- Validator .ensureTrue ((subInitial != null ) ||
945
- ((subAny != null ) && (subAny .length > 0 )) ||
946
- (subFinal != null ));
987
+ Validator .ensureTrue (
988
+ (((subInitial != null ) && (subInitial .length > 0 )) ||
989
+ ((subAny != null ) && (subAny .length > 0 ) &&
990
+ (subAny [0 ].length > 0 )) ||
991
+ ((subFinal != null ) && (subFinal .length > 0 ))),
992
+ "At least one substring filter component must be non-null and " +
993
+ "non-empty" );
947
994
948
995
final ASN1OctetString subInitialOS ;
949
- if (subInitial == null )
996
+ if (( subInitial == null ) || ( subInitial . length == 0 ) )
950
997
{
951
998
subInitialOS = null ;
952
999
}
@@ -962,15 +1009,34 @@ public static Filter createSubstringFilter(
962
1009
}
963
1010
else
964
1011
{
965
- subAnyArray = new ASN1OctetString [subAny .length ];
966
- for (int i =0 ; i < subAny .length ; i ++)
1012
+ if (subAny .length == 1 )
967
1013
{
968
- subAnyArray [i ] = new ASN1OctetString (subAny [i ]);
1014
+ if (subAny [0 ].length == 0 )
1015
+ {
1016
+ subAnyArray = NO_SUB_ANY ;
1017
+ }
1018
+ else
1019
+ {
1020
+ subAnyArray = new ASN1OctetString []
1021
+ {
1022
+ new ASN1OctetString (subAny [0 ])
1023
+ };
1024
+ }
1025
+ }
1026
+ else
1027
+ {
1028
+ subAnyArray = new ASN1OctetString [subAny .length ];
1029
+ for (int i =0 ; i < subAny .length ; i ++)
1030
+ {
1031
+ Validator .ensureTrue ((subAny [i ].length > 0 ),
1032
+ "Individual substring filter components must not be empty" );
1033
+ subAnyArray [i ] = new ASN1OctetString (subAny [i ]);
1034
+ }
969
1035
}
970
1036
}
971
1037
972
1038
final ASN1OctetString subFinalOS ;
973
- if (subFinal == null )
1039
+ if (( subFinal == null ) || ( subFinal . length == 0 ) )
974
1040
{
975
1041
subFinalOS = null ;
976
1042
}
@@ -994,9 +1060,14 @@ public static Filter createSubstringFilter(
994
1060
* @param attributeName The attribute name for this substring filter. It
995
1061
* must not be {@code null}.
996
1062
* @param subInitial The subInitial component for this substring filter.
1063
+ * It may be {@code null} if there is no subInitial
1064
+ * component, but it must not be empty.
997
1065
* @param subAny The set of subAny components for this substring
998
- * filter.
1066
+ * filter. It may be {@code null} or empty if there
1067
+ * are no subAny components.
999
1068
* @param subFinal The subFinal component for this substring filter.
1069
+ * It may be {@code null} if there is no subFinal
1070
+ * component, but it must not be empty.
1000
1071
*
1001
1072
* @return The created substring search filter.
1002
1073
*/
@@ -1038,7 +1109,7 @@ static Filter createSubstringFilter(@NotNull final String attributeName,
1038
1109
* @param attributeName The attribute name for this substring filter. It
1039
1110
* must not be {@code null}.
1040
1111
* @param subInitial The subInitial component for this substring filter.
1041
- * It must not be {@code null}.
1112
+ * It must not be {@code null} or empty .
1042
1113
*
1043
1114
* @return The created substring search filter.
1044
1115
*/
@@ -1062,7 +1133,7 @@ public static Filter subInitial(@NotNull final String attributeName,
1062
1133
* @param attributeName The attribute name for this substring filter. It
1063
1134
* must not be {@code null}.
1064
1135
* @param subInitial The subInitial component for this substring filter.
1065
- * It must not be {@code null}.
1136
+ * It must not be {@code null} or empty .
1066
1137
*
1067
1138
* @return The created substring search filter.
1068
1139
*/
@@ -1082,7 +1153,7 @@ public static Filter subInitial(@NotNull final String attributeName,
1082
1153
* @param attributeName The attribute name for this substring filter. It
1083
1154
* must not be {@code null}.
1084
1155
* @param subInitial The subInitial component for this substring filter.
1085
- * It must not be {@code null}.
1156
+ * It must not be {@code null} or empty .
1086
1157
*
1087
1158
* @return The created substring search filter.
1088
1159
*/
@@ -1103,7 +1174,7 @@ public static Filter createSubInitialFilter(
1103
1174
* @param attributeName The attribute name for this substring filter. It
1104
1175
* must not be {@code null}.
1105
1176
* @param subInitial The subInitial component for this substring filter.
1106
- * It must not be {@code null}.
1177
+ * It must not be {@code null} or empty .
1107
1178
*
1108
1179
* @return The created substring search filter.
1109
1180
*/
@@ -1216,7 +1287,7 @@ public static Filter createSubAnyFilter(@NotNull final String attributeName,
1216
1287
* @param attributeName The attribute name for this substring filter. It
1217
1288
* must not be {@code null}.
1218
1289
* @param subFinal The subFinal component for this substring filter.
1219
- * It must not be {@code null}.
1290
+ * It must not be {@code null} or empty .
1220
1291
*
1221
1292
* @return The created substring search filter.
1222
1293
*/
@@ -1240,7 +1311,7 @@ public static Filter subFinal(@NotNull final String attributeName,
1240
1311
* @param attributeName The attribute name for this substring filter. It
1241
1312
* must not be {@code null}.
1242
1313
* @param subFinal The subFinal component for this substring filter.
1243
- * It must not be {@code null}.
1314
+ * It must not be {@code null} or empty .
1244
1315
*
1245
1316
* @return The created substring search filter.
1246
1317
*/
@@ -1260,7 +1331,7 @@ public static Filter subFinal(@NotNull final String attributeName,
1260
1331
* @param attributeName The attribute name for this substring filter. It
1261
1332
* must not be {@code null}.
1262
1333
* @param subFinal The subFinal component for this substring filter.
1263
- * It must not be {@code null}.
1334
+ * It must not be {@code null} or empty .
1264
1335
*
1265
1336
* @return The created substring search filter.
1266
1337
*/
@@ -1280,7 +1351,7 @@ public static Filter createSubFinalFilter(@NotNull final String attributeName,
1280
1351
* @param attributeName The attribute name for this substring filter. It
1281
1352
* must not be {@code null}.
1282
1353
* @param subFinal The subFinal component for this substring filter.
1283
- * It must not be {@code null}.
1354
+ * It must not be {@code null} or empty .
1284
1355
*
1285
1356
* @return The created substring search filter.
1286
1357
*/
0 commit comments