22
22
import java .util .Collections ;
23
23
import java .util .LinkedHashSet ;
24
24
import java .util .List ;
25
+ import java .util .Objects ;
25
26
import java .util .Set ;
26
27
import java .util .regex .Matcher ;
27
28
import java .util .regex .Pattern ;
@@ -138,13 +139,13 @@ public CorsConfiguration(CorsConfiguration other) {
138
139
* However an instance of this class is often initialized further, e.g. for
139
140
* {@code @CrossOrigin}, via {@link #applyPermitDefaultValues()}.
140
141
*/
141
- public void setAllowedOrigins (@ Nullable List <String > allowedOrigins ) {
142
- this .allowedOrigins = (allowedOrigins != null ?
143
- allowedOrigins .stream ().map (this ::trimTrailingSlash ).collect (Collectors .toList ()) : null );
142
+ public void setAllowedOrigins (@ Nullable List <String > origins ) {
143
+ this .allowedOrigins = (origins == null ? null :
144
+ origins .stream ().filter ( Objects :: nonNull ). map (this ::trimTrailingSlash ).collect (Collectors .toList ()));
144
145
}
145
146
146
147
private String trimTrailingSlash (String origin ) {
147
- return origin .endsWith ("/" ) ? origin .substring (0 , origin .length () - 1 ) : origin ;
148
+ return ( origin .endsWith ("/" ) ? origin .substring (0 , origin .length () - 1 ) : origin ) ;
148
149
}
149
150
150
151
/**
@@ -158,7 +159,11 @@ public List<String> getAllowedOrigins() {
158
159
/**
159
160
* Variant of {@link #setAllowedOrigins} for adding one origin at a time.
160
161
*/
162
+ @ SuppressWarnings ("ConstantConditions" )
161
163
public void addAllowedOrigin (String origin ) {
164
+ if (origin == null ) {
165
+ return ;
166
+ }
162
167
if (this .allowedOrigins == null ) {
163
168
this .allowedOrigins = new ArrayList <>(4 );
164
169
}
@@ -220,7 +225,11 @@ public List<String> getAllowedOriginPatterns() {
220
225
* Variant of {@link #setAllowedOriginPatterns} for adding one origin at a time.
221
226
* @since 5.3
222
227
*/
228
+ @ SuppressWarnings ("ConstantConditions" )
223
229
public void addAllowedOriginPattern (String originPattern ) {
230
+ if (originPattern == null ) {
231
+ return ;
232
+ }
224
233
if (this .allowedOriginPatterns == null ) {
225
234
this .allowedOriginPatterns = new ArrayList <>(4 );
226
235
}
0 commit comments