Skip to content

Commit 1a56023

Browse files
ngocnhan-tran1996jzheaux
authored andcommitted
Use Spring Framework Nullability Annotations
Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent 6873685 commit 1a56023

File tree

13 files changed

+41
-38
lines changed

13 files changed

+41
-38
lines changed

config/src/main/java/org/springframework/security/config/annotation/method/configuration/DeferringMethodInterceptor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
import org.aopalliance.aop.Advice;
2222
import org.aopalliance.intercept.MethodInvocation;
23-
import org.jetbrains.annotations.NotNull;
24-
import org.jetbrains.annotations.Nullable;
2523

2624
import org.springframework.aop.Pointcut;
25+
import org.springframework.lang.NonNull;
26+
import org.springframework.lang.Nullable;
2727
import org.springframework.security.authorization.method.AuthorizationAdvisor;
2828
import org.springframework.util.function.SingletonSupplier;
2929

@@ -40,7 +40,7 @@ final class DeferringMethodInterceptor<M extends AuthorizationAdvisor> implement
4040

4141
@Nullable
4242
@Override
43-
public Object invoke(@NotNull MethodInvocation invocation) throws Throwable {
43+
public Object invoke(@NonNull MethodInvocation invocation) throws Throwable {
4444
return this.delegate.get().invoke(invocation);
4545
}
4646

config/src/main/java/org/springframework/security/config/annotation/method/configuration/MethodSecurityAdvisorRegistrar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.aopalliance.aop.Advice;
2020
import org.aopalliance.intercept.MethodInterceptor;
2121
import org.aopalliance.intercept.MethodInvocation;
22-
import org.jetbrains.annotations.NotNull;
23-
import org.jetbrains.annotations.Nullable;
2422

2523
import org.springframework.aop.Advisor;
2624
import org.springframework.aop.Pointcut;
@@ -33,6 +31,8 @@
3331
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
3432
import org.springframework.core.Ordered;
3533
import org.springframework.core.type.AnnotationMetadata;
34+
import org.springframework.lang.NonNull;
35+
import org.springframework.lang.Nullable;
3636
import org.springframework.security.authorization.method.AuthorizationAdvisor;
3737

3838
class MethodSecurityAdvisorRegistrar implements ImportBeanDefinitionRegistrar {
@@ -100,7 +100,7 @@ public int getOrder() {
100100

101101
@Nullable
102102
@Override
103-
public Object invoke(@NotNull MethodInvocation invocation) throws Throwable {
103+
public Object invoke(@NonNull MethodInvocation invocation) throws Throwable {
104104
return this.advisor.invoke(invocation);
105105
}
106106

config/src/main/java/org/springframework/security/config/web/PathPatternRequestMatcherBuilderFactoryBean.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.security.config.web;
1818

19-
import reactor.util.annotation.NonNull;
20-
2119
import org.springframework.beans.BeansException;
2220
import org.springframework.beans.factory.BeanFactory;
2321
import org.springframework.beans.factory.BeanFactoryAware;
@@ -27,6 +25,7 @@
2725
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2826
import org.springframework.context.ApplicationContext;
2927
import org.springframework.context.ApplicationContextAware;
28+
import org.springframework.lang.NonNull;
3029
import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;
3130
import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher;
3231
import org.springframework.web.util.pattern.PathPatternParser;

config/src/main/java/org/springframework/security/config/web/server/OAuth2ErrorEncoder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24-
import org.jetbrains.annotations.NotNull;
2524
import org.reactivestreams.Publisher;
2625
import reactor.core.publisher.Flux;
2726
import reactor.core.publisher.Mono;
@@ -34,14 +33,15 @@
3433
import org.springframework.http.MediaType;
3534
import org.springframework.http.codec.HttpMessageEncoder;
3635
import org.springframework.http.converter.HttpMessageConverter;
36+
import org.springframework.lang.NonNull;
3737
import org.springframework.security.oauth2.core.OAuth2Error;
3838
import org.springframework.util.MimeType;
3939

4040
class OAuth2ErrorEncoder implements HttpMessageEncoder<OAuth2Error> {
4141

4242
private final HttpMessageConverter<Object> messageConverter = HttpMessageConverters.getJsonMessageConverter();
4343

44-
@NotNull
44+
@NonNull
4545
@Override
4646
public List<MediaType> getStreamingMediaTypes() {
4747
return List.of();
@@ -52,7 +52,7 @@ public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
5252
return getEncodableMimeTypes().contains(mimeType);
5353
}
5454

55-
@NotNull
55+
@NonNull
5656
@Override
5757
public Flux<DataBuffer> encode(Publisher<? extends OAuth2Error> error, DataBufferFactory bufferFactory,
5858
ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
@@ -68,7 +68,7 @@ public Flux<DataBuffer> encode(Publisher<? extends OAuth2Error> error, DataBuffe
6868
}).map(bufferFactory::wrap).flux();
6969
}
7070

71-
@NotNull
71+
@NonNull
7272
@Override
7373
public List<MimeType> getEncodableMimeTypes() {
7474
return List.of(MediaType.APPLICATION_JSON);
@@ -78,13 +78,13 @@ private static class ByteArrayHttpOutputMessage implements HttpOutputMessage {
7878

7979
private final ByteArrayOutputStream body = new ByteArrayOutputStream();
8080

81-
@NotNull
81+
@NonNull
8282
@Override
8383
public ByteArrayOutputStream getBody() {
8484
return this.body;
8585
}
8686

87-
@NotNull
87+
@NonNull
8888
@Override
8989
public HttpHeaders getHeaders() {
9090
return new HttpHeaders();

config/src/test/java/org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
import java.util.Collections;
2020

21-
import org.jetbrains.annotations.NotNull;
2221
import org.junit.jupiter.api.Test;
2322
import org.junit.jupiter.api.extension.ExtendWith;
2423
import reactor.core.publisher.Mono;
2524

2625
import org.springframework.context.annotation.Bean;
2726
import org.springframework.context.annotation.Configuration;
2827
import org.springframework.http.HttpStatus;
28+
import org.springframework.lang.NonNull;
2929
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
3030
import org.springframework.mock.web.server.MockServerWebExchange;
3131
import org.springframework.security.config.test.SpringTestContext;
@@ -109,7 +109,7 @@ public void loadConfigWhenBeanProxyingEnabledAndSubclassThenWebFilterChainProxyE
109109
assertThat(webFilterChainProxy).isNotNull();
110110
}
111111

112-
private static @NotNull DefaultWebFilterChain emptyChain() {
112+
private static @NonNull DefaultWebFilterChain emptyChain() {
113113
return new DefaultWebFilterChain((webExchange) -> Mono.empty(), Collections.emptyList());
114114
}
115115

config/src/test/java/org/springframework/security/config/http/MiscHttpConfigTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import jakarta.servlet.http.HttpServletResponseWrapper;
4646
import org.apache.http.HttpStatus;
4747
import org.assertj.core.api.iterable.Extractor;
48-
import org.jetbrains.annotations.NotNull;
4948
import org.junit.jupiter.api.Test;
5049
import org.junit.jupiter.api.extension.ExtendWith;
5150
import org.mockito.stubbing.Answer;
@@ -55,6 +54,7 @@
5554
import org.springframework.beans.factory.BeanCreationException;
5655
import org.springframework.beans.factory.annotation.Autowired;
5756
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
57+
import org.springframework.lang.NonNull;
5858
import org.springframework.mock.web.MockHttpServletRequest;
5959
import org.springframework.mock.web.MockHttpServletResponse;
6060
import org.springframework.mock.web.MockHttpSession;
@@ -908,17 +908,17 @@ private List<Filter> getFilters(String url) {
908908
return proxy.getFilters(url);
909909
}
910910

911-
@NotNull
911+
@NonNull
912912
private static RequestPostProcessor userCredentials() {
913913
return httpBasic("user", "password");
914914
}
915915

916-
@NotNull
916+
@NonNull
917917
private static RequestPostProcessor adminCredentials() {
918918
return httpBasic("admin", "password");
919919
}
920920

921-
@NotNull
921+
@NonNull
922922
private static RequestPostProcessor postCredentials() {
923923
return httpBasic("poster", "password");
924924
}

config/src/test/java/org/springframework/security/config/method/MethodSecurityBeanDefinitionParserTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
import org.aopalliance.intercept.MethodInterceptor;
2626
import org.aopalliance.intercept.MethodInvocation;
27-
import org.jetbrains.annotations.NotNull;
2827
import org.junit.jupiter.api.Test;
2928
import org.junit.jupiter.api.extension.ExtendWith;
3029

3130
import org.springframework.beans.factory.annotation.Autowired;
3231
import org.springframework.core.annotation.AnnotationConfigurationException;
32+
import org.springframework.lang.NonNull;
3333
import org.springframework.lang.Nullable;
3434
import org.springframework.security.access.AccessDeniedException;
3535
import org.springframework.security.access.PermissionEvaluator;
@@ -474,7 +474,7 @@ static class MyAdvice implements MethodInterceptor {
474474

475475
@Nullable
476476
@Override
477-
public Object invoke(@NotNull MethodInvocation invocation) {
477+
public Object invoke(@NonNull MethodInvocation invocation) {
478478
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
479479
if ("bob".equals(auth.getName())) {
480480
return "granted";

core/src/test/java/org/springframework/security/authorization/AuthorizationAdvisorProxyFactoryTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636

3737
import com.fasterxml.jackson.core.JsonProcessingException;
3838
import com.fasterxml.jackson.databind.ObjectMapper;
39-
import org.jetbrains.annotations.NotNull;
4039
import org.junit.jupiter.api.Test;
4140

4241
import org.springframework.aop.Pointcut;
4342
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
43+
import org.springframework.lang.NonNull;
4444
import org.springframework.security.access.AccessDeniedException;
4545
import org.springframework.security.access.prepost.PreAuthorize;
4646
import org.springframework.security.authentication.TestAuthentication;
@@ -443,7 +443,7 @@ public String getLastName() {
443443
}
444444

445445
@Override
446-
public int compareTo(@NotNull User that) {
446+
public int compareTo(@NonNull User that) {
447447
return this.id.compareTo(that.getId());
448448
}
449449

@@ -453,7 +453,7 @@ static class UserRepository implements Iterable<User> {
453453

454454
List<User> users = List.of(new User("1", "first", "last"));
455455

456-
@NotNull
456+
@NonNull
457457
@Override
458458
public Iterator<User> iterator() {
459459
return this.users.iterator();

core/src/test/java/org/springframework/security/authorization/ReactiveAuthorizationAdvisorProxyFactoryTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import java.util.Iterator;
2020
import java.util.List;
2121

22-
import org.jetbrains.annotations.NotNull;
2322
import org.junit.jupiter.api.Test;
2423
import reactor.core.publisher.Flux;
2524
import reactor.core.publisher.Mono;
2625
import reactor.test.StepVerifier;
2726

2827
import org.springframework.aop.Pointcut;
28+
import org.springframework.lang.NonNull;
2929
import org.springframework.security.access.AccessDeniedException;
3030
import org.springframework.security.access.prepost.PreAuthorize;
3131
import org.springframework.security.authentication.TestAuthentication;
@@ -193,7 +193,7 @@ public Mono<String> getLastName() {
193193
}
194194

195195
@Override
196-
public int compareTo(@NotNull User that) {
196+
public int compareTo(@NonNull User that) {
197197
return this.id.compareTo(that.getId());
198198
}
199199

@@ -207,7 +207,7 @@ Flux<User> findAll() {
207207
return Flux.fromIterable(this.users);
208208
}
209209

210-
@NotNull
210+
@NonNull
211211
@Override
212212
public Iterator<User> iterator() {
213213
return this.users.iterator();

etc/checkstyle/checkstyle.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@
4747
value="String.toUpperCase() should be String.toUpperCase(Locale.ROOT) or String.toUpperCase(Locale.ENGLISH)"/>
4848
<property name="ignoreComments" value="true"/>
4949
</module>
50+
<module name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck">
51+
<property name="id" value="bannedImports"/>
52+
<property name="regexp" value="true"/>
53+
<property name="illegalPkgs" value="org.jetbrains.annotations, reactor.util.annotation, javax.annotation"/>
54+
</module>
5055
</module>
5156
</module>

0 commit comments

Comments
 (0)