Skip to content

Commit c292a89

Browse files
committed
Http(Async)Client not actually nullable, plus MethodInterceptor nullability
Issue: SPR-15720
1 parent 1e66191 commit c292a89

File tree

14 files changed

+35
-24
lines changed

14 files changed

+35
-24
lines changed

spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public AsyncExecutionInterceptor(@Nullable Executor defaultExecutor, AsyncUncaug
9898
* otherwise.
9999
*/
100100
@Override
101+
@Nullable
101102
public Object invoke(final MethodInvocation invocation) throws Throwable {
102103
Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
103104
Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);

spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import org.springframework.aop.DynamicIntroductionAdvice;
2525
import org.springframework.aop.IntroductionInterceptor;
2626
import org.springframework.aop.ProxyMethodInvocation;
27+
import org.springframework.lang.Nullable;
2728
import org.springframework.util.ReflectionUtils;
2829

2930
/**
@@ -85,6 +86,7 @@ public DelegatePerTargetObjectIntroductionInterceptor(Class<?> defaultImplType,
8586
* method, which handles introduced interfaces and forwarding to the target.
8687
*/
8788
@Override
89+
@Nullable
8890
public Object invoke(MethodInvocation mi) throws Throwable {
8991
if (isMethodOnIntroducedInterface(mi)) {
9092
Object delegate = getIntroductionDelegateFor(mi.getThis());

spring-aop/src/main/java/org/springframework/aop/support/DelegatingIntroductionInterceptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import org.springframework.aop.DynamicIntroductionAdvice;
2222
import org.springframework.aop.IntroductionInterceptor;
2323
import org.springframework.aop.ProxyMethodInvocation;
24+
import org.springframework.lang.Nullable;
2425
import org.springframework.util.Assert;
2526

2627
/**
@@ -100,6 +101,7 @@ private void init(Object delegate) {
100101
* method, which handles introduced interfaces and forwarding to the target.
101102
*/
102103
@Override
104+
@Nullable
103105
public Object invoke(MethodInvocation mi) throws Throwable {
104106
if (isMethodOnIntroducedInterface(mi)) {
105107
// Using the following method rather than direct reflection, we

spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.aopalliance.intercept.MethodInterceptor;
2323
import org.aopalliance.intercept.MethodInvocation;
2424

25+
import org.springframework.lang.Nullable;
26+
2527
/**
2628
* AOP Alliance MethodInterceptor for declarative cache
2729
* management using the common Spring caching infrastructure
@@ -42,6 +44,7 @@
4244
public class CacheInterceptor extends CacheAspectSupport implements MethodInterceptor, Serializable {
4345

4446
@Override
47+
@Nullable
4548
public Object invoke(final MethodInvocation invocation) throws Throwable {
4649
Method method = invocation.getMethod();
4750

spring-context/src/main/java/org/springframework/ejb/access/AbstractSlsbInvokerInterceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ protected boolean isHomeRefreshable() {
187187
* {@link #invokeInContext}.
188188
*/
189189
@Override
190+
@Nullable
190191
public Object invoke(MethodInvocation invocation) throws Throwable {
191192
Context ctx = (this.exposeAccessContext ? getJndiTemplate().getContext() : null);
192193
try {

spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ protected boolean isPrepared() {
354354
* @see #handleConnectFailure
355355
*/
356356
@Override
357+
@Nullable
357358
public Object invoke(MethodInvocation invocation) throws Throwable {
358359
// Lazily connect to MBeanServer if necessary.
359360
synchronized (this.preparationMonitor) {

spring-jms/src/main/java/org/springframework/jms/remoting/JmsInvokerClientInterceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public void afterPropertiesSet() {
192192

193193

194194
@Override
195+
@Nullable
195196
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
196197
if (AopUtils.isToStringMethod(methodInvocation.getMethod())) {
197198
return "JMS invoker proxy for queue [" + this.queue + "]";

spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,7 @@ public int getTimeout() {
420420
conHolder.setTimeoutInSeconds(timeoutToUse);
421421
}
422422
if (logger.isDebugEnabled()) {
423-
logger.debug("Exposing JPA transaction as JDBC transaction [" +
424-
conHolder.getConnectionHandle() + "]");
423+
logger.debug("Exposing JPA transaction as JDBC transaction [" + conHandle + "]");
425424
}
426425
TransactionSynchronizationManager.bindResource(getDataSource(), conHolder);
427426
txObject.setConnectionHolder(conHolder);
@@ -601,13 +600,16 @@ protected void doCleanupAfterCompletion(Object transaction) {
601600
// Remove the JDBC connection holder from the thread, if exposed.
602601
if (getDataSource() != null && txObject.hasConnectionHolder()) {
603602
TransactionSynchronizationManager.unbindResource(getDataSource());
604-
try {
605-
getJpaDialect().releaseJdbcConnection(txObject.getConnectionHolder().getConnectionHandle(),
606-
txObject.getEntityManagerHolder().getEntityManager());
607-
}
608-
catch (Exception ex) {
609-
// Just log it, to keep a transaction-related exception.
610-
logger.error("Could not close JDBC connection after transaction", ex);
603+
ConnectionHandle conHandle = txObject.getConnectionHolder().getConnectionHandle();
604+
if (conHandle != null) {
605+
try {
606+
getJpaDialect().releaseJdbcConnection(conHandle,
607+
txObject.getEntityManagerHolder().getEntityManager());
608+
}
609+
catch (Exception ex) {
610+
// Just log it, to keep a transaction-related exception.
611+
logger.error("Could not close JDBC connection after transaction", ex);
612+
}
611613
}
612614
}
613615

spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionInterceptor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.springframework.aop.support.AopUtils;
2929
import org.springframework.beans.factory.BeanFactory;
30+
import org.springframework.lang.Nullable;
3031
import org.springframework.transaction.PlatformTransactionManager;
3132

3233
/**
@@ -86,6 +87,7 @@ public TransactionInterceptor(PlatformTransactionManager ptm, TransactionAttribu
8687

8788

8889
@Override
90+
@Nullable
8991
public Object invoke(final MethodInvocation invocation) throws Throwable {
9092
// Work out the target class: may be {@code null}.
9193
// The TransactionAttributeSource should be passed the target class

spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequestFactory.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import org.springframework.beans.factory.InitializingBean;
3535
import org.springframework.http.HttpMethod;
36-
import org.springframework.lang.Nullable;
3736
import org.springframework.util.Assert;
3837

3938
/**
@@ -51,7 +50,6 @@
5150
public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsClientHttpRequestFactory
5251
implements AsyncClientHttpRequestFactory, InitializingBean {
5352

54-
@Nullable
5553
private HttpAsyncClient asyncClient;
5654

5755

@@ -72,7 +70,7 @@ public HttpComponentsAsyncClientHttpRequestFactory() {
7270
*/
7371
public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient) {
7472
super();
75-
setAsyncClient(asyncClient);
73+
this.asyncClient = asyncClient;
7674
}
7775

7876
/**
@@ -82,7 +80,7 @@ public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient)
8280
*/
8381
public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyncClient) {
8482
super();
85-
setAsyncClient(asyncClient);
83+
this.asyncClient = asyncClient;
8684
}
8785

8886
/**
@@ -94,7 +92,7 @@ public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyn
9492
*/
9593
public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, HttpAsyncClient asyncClient) {
9694
super(httpClient);
97-
setAsyncClient(asyncClient);
95+
this.asyncClient = asyncClient;
9896
}
9997

10098
/**
@@ -107,7 +105,7 @@ public HttpComponentsAsyncClientHttpRequestFactory(
107105
CloseableHttpClient httpClient, CloseableHttpAsyncClient asyncClient) {
108106

109107
super(httpClient);
110-
setAsyncClient(asyncClient);
108+
this.asyncClient = asyncClient;
111109
}
112110

113111

@@ -128,7 +126,6 @@ public void setAsyncClient(HttpAsyncClient asyncClient) {
128126
* @since 4.3.10
129127
* @see #getHttpClient()
130128
*/
131-
@Nullable
132129
public HttpAsyncClient getAsyncClient() {
133130
return this.asyncClient;
134131
}
@@ -150,7 +147,7 @@ public void setHttpAsyncClient(CloseableHttpAsyncClient asyncClient) {
150147
*/
151148
@Deprecated
152149
public CloseableHttpAsyncClient getHttpAsyncClient() {
153-
Assert.state(this.asyncClient == null || this.asyncClient instanceof CloseableHttpAsyncClient,
150+
Assert.state(this.asyncClient instanceof CloseableHttpAsyncClient,
154151
"No CloseableHttpAsyncClient - use getAsyncClient() instead");
155152
return (CloseableHttpAsyncClient) this.asyncClient;
156153
}
@@ -163,7 +160,6 @@ public void afterPropertiesSet() {
163160

164161
private HttpAsyncClient startAsyncClient() {
165162
HttpAsyncClient client = getAsyncClient();
166-
Assert.state(client != null, "No HttpAsyncClient set");
167163
if (client instanceof CloseableHttpAsyncClient) {
168164
CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) client;
169165
if (!closeableAsyncClient.isRunning()) {

spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
*/
6060
public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
6161

62-
@Nullable
6362
private HttpClient httpClient;
6463

6564
@Nullable
@@ -82,7 +81,7 @@ public HttpComponentsClientHttpRequestFactory() {
8281
* @param httpClient the HttpClient instance to use for this request factory
8382
*/
8483
public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) {
85-
setHttpClient(httpClient);
84+
this.httpClient = httpClient;
8685
}
8786

8887

@@ -99,7 +98,6 @@ public void setHttpClient(HttpClient httpClient) {
9998
* Return the {@code HttpClient} used for
10099
* {@linkplain #createRequest(URI, HttpMethod) synchronous execution}.
101100
*/
102-
@Nullable
103101
public HttpClient getHttpClient() {
104102
return this.httpClient;
105103
}
@@ -156,7 +154,6 @@ public void setBufferRequestBody(boolean bufferRequestBody) {
156154
@Override
157155
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
158156
HttpClient client = getHttpClient();
159-
Assert.state(client != null, "No HttpClient set");
160157

161158
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
162159
postProcessHttpRequest(httpRequest);

spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
*/
4444
public class Jackson2JsonEncoder extends AbstractJackson2Encoder {
4545

46+
@Nullable
4647
private final PrettyPrinter ssePrettyPrinter;
4748

4849

spring-web/src/main/java/org/springframework/remoting/jaxws/JaxWsPortClientInterceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ protected Object getPortStub() {
494494

495495

496496
@Override
497+
@Nullable
497498
public Object invoke(MethodInvocation invocation) throws Throwable {
498499
if (AopUtils.isToStringMethod(invocation.getMethod())) {
499500
return "JAX-WS proxy for port [" + getPortName() + "] of service [" + getServiceName() + "]";

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ else if (ReflectionUtils.isObjectMethod(method)) {
753753
}
754754

755755
@Override
756+
@Nullable
756757
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable {
757758
return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null);
758759
}

0 commit comments

Comments
 (0)