File tree Expand file tree Collapse file tree 6 files changed +61
-9
lines changed
main/java/org/springframework/security/web
test/java/org/springframework/security/web Expand file tree Collapse file tree 6 files changed +61
-9
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@ public MediaTypeServerWebExchangeMatcher(MediaType... matchingMediaTypes) {
66
66
*/
67
67
public MediaTypeServerWebExchangeMatcher (Collection <MediaType > matchingMediaTypes ) {
68
68
Assert .notEmpty (matchingMediaTypes , "matchingMediaTypes cannot be null" );
69
- Assert .isTrue (! matchingMediaTypes . contains ( null ) ,
69
+ Assert .noNullElements ( matchingMediaTypes ,
70
70
() -> "matchingMediaTypes cannot contain null. Got " + matchingMediaTypes );
71
71
this .matchingMediaTypes = matchingMediaTypes ;
72
72
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ public final class AndRequestMatcher implements RequestMatcher {
45
45
*/
46
46
public AndRequestMatcher (List <RequestMatcher > requestMatchers ) {
47
47
Assert .notEmpty (requestMatchers , "requestMatchers must contain a value" );
48
- Assert .isTrue (! requestMatchers . contains ( null ) , "requestMatchers cannot contain null values" );
48
+ Assert .noNullElements ( requestMatchers , "requestMatchers cannot contain null values" );
49
49
this .requestMatchers = requestMatchers ;
50
50
}
51
51
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ public final class OrRequestMatcher implements RequestMatcher {
40
40
*/
41
41
public OrRequestMatcher (List <RequestMatcher > requestMatchers ) {
42
42
Assert .notEmpty (requestMatchers , "requestMatchers must contain a value" );
43
- Assert .isTrue (! requestMatchers . contains ( null ) , "requestMatchers cannot contain null values" );
43
+ Assert .noNullElements ( requestMatchers , "requestMatchers cannot contain null values" );
44
44
this .requestMatchers = requestMatchers ;
45
45
}
46
46
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .security .web .server .util .matcher ;
18
18
19
+ import java .util .ArrayList ;
20
+ import java .util .Arrays ;
19
21
import java .util .Collections ;
20
22
import java .util .List ;
21
23
@@ -43,6 +45,21 @@ public void constructorMediaTypeArrayWhenNullThenThrowsIllegalArgumentException(
43
45
assertThatIllegalArgumentException ().isThrownBy (() -> new MediaTypeServerWebExchangeMatcher (types ));
44
46
}
45
47
48
+ // gh-10703
49
+ @ Test
50
+ public void constructorListOfDoesNotThrowNullPointerException () {
51
+ List <MediaType > mediaTypes = new ArrayList <MediaType >(Arrays .asList (MediaType .ALL )) {
52
+ @ Override
53
+ public boolean contains (Object o ) {
54
+ if (o == null ) {
55
+ throw new NullPointerException ();
56
+ }
57
+ return super .contains (o );
58
+ }
59
+ };
60
+ new MediaTypeServerWebExchangeMatcher (mediaTypes );
61
+ }
62
+
46
63
@ Test
47
64
public void constructorMediaTypeArrayWhenContainsNullThenThrowsIllegalArgumentException () {
48
65
MediaType [] types = { null };
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .security .web .util .matcher ;
18
18
19
+ import java .util .ArrayList ;
19
20
import java .util .Arrays ;
20
21
import java .util .Collections ;
21
22
import java .util .List ;
@@ -55,6 +56,22 @@ public void constructorNullArray() {
55
56
assertThatNullPointerException ().isThrownBy (() -> new AndRequestMatcher ((RequestMatcher []) null ));
56
57
}
57
58
59
+ // gh-10703
60
+ @ Test
61
+ public void constructorListOfDoesNotThrowNullPointer () {
62
+ List <RequestMatcher > requestMatchers = new ArrayList <RequestMatcher >(
63
+ Arrays .asList (AnyRequestMatcher .INSTANCE )) {
64
+ @ Override
65
+ public boolean contains (Object o ) {
66
+ if (o == null ) {
67
+ throw new NullPointerException ();
68
+ }
69
+ return super .contains (o );
70
+ }
71
+ };
72
+ new AndRequestMatcher (requestMatchers );
73
+ }
74
+
58
75
@ Test
59
76
public void constructorArrayContainsNull () {
60
77
assertThatIllegalArgumentException ().isThrownBy (() -> new AndRequestMatcher ((RequestMatcher ) null ));
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .security .web .util .matcher ;
18
18
19
+ import java .util .ArrayList ;
19
20
import java .util .Arrays ;
20
21
import java .util .Collections ;
21
22
import java .util .List ;
@@ -55,6 +56,23 @@ public void constructorNullArray() {
55
56
assertThatNullPointerException ().isThrownBy (() -> new OrRequestMatcher ((RequestMatcher []) null ));
56
57
}
57
58
59
+ // gh-10703
60
+ @ Test
61
+ public void constructorListOfDoesNotThrowNullPointer () {
62
+ // emulate List.of for pre-JDK 9 builds
63
+ List <RequestMatcher > requestMatchers = new ArrayList <RequestMatcher >(
64
+ Arrays .asList (AnyRequestMatcher .INSTANCE )) {
65
+ @ Override
66
+ public boolean contains (Object o ) {
67
+ if (o == null ) {
68
+ throw new NullPointerException ();
69
+ }
70
+ return super .contains (o );
71
+ }
72
+ };
73
+ new OrRequestMatcher (requestMatchers );
74
+ }
75
+
58
76
@ Test
59
77
public void constructorArrayContainsNull () {
60
78
assertThatIllegalArgumentException ().isThrownBy (() -> new OrRequestMatcher ((RequestMatcher ) null ));
You can’t perform that action at this time.
0 commit comments