Http(Async)Client not actually nullable, plus MethodInterceptor nullability

Issue: SPR-15720
This commit is contained in:
Juergen Hoeller 2017-07-19 00:15:37 +02:00
parent 1e66191cbd
commit c292a89b24
14 changed files with 35 additions and 24 deletions

View File

@ -98,6 +98,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
* otherwise.
*/
@Override
@Nullable
public Object invoke(final MethodInvocation invocation) throws Throwable {
Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,6 +24,7 @@ import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.DynamicIntroductionAdvice;
import org.springframework.aop.IntroductionInterceptor;
import org.springframework.aop.ProxyMethodInvocation;
import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
/**
@ -85,6 +86,7 @@ public class DelegatePerTargetObjectIntroductionInterceptor extends Introduction
* method, which handles introduced interfaces and forwarding to the target.
*/
@Override
@Nullable
public Object invoke(MethodInvocation mi) throws Throwable {
if (isMethodOnIntroducedInterface(mi)) {
Object delegate = getIntroductionDelegateFor(mi.getThis());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.DynamicIntroductionAdvice;
import org.springframework.aop.IntroductionInterceptor;
import org.springframework.aop.ProxyMethodInvocation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@ -100,6 +101,7 @@ public class DelegatingIntroductionInterceptor extends IntroductionInfoSupport
* method, which handles introduced interfaces and forwarding to the target.
*/
@Override
@Nullable
public Object invoke(MethodInvocation mi) throws Throwable {
if (isMethodOnIntroducedInterface(mi)) {
// Using the following method rather than direct reflection, we

View File

@ -22,6 +22,8 @@ import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.lang.Nullable;
/**
* AOP Alliance MethodInterceptor for declarative cache
* management using the common Spring caching infrastructure
@ -42,6 +44,7 @@ import org.aopalliance.intercept.MethodInvocation;
public class CacheInterceptor extends CacheAspectSupport implements MethodInterceptor, Serializable {
@Override
@Nullable
public Object invoke(final MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();

View File

@ -187,6 +187,7 @@ public abstract class AbstractSlsbInvokerInterceptor extends JndiObjectLocator
* {@link #invokeInContext}.
*/
@Override
@Nullable
public Object invoke(MethodInvocation invocation) throws Throwable {
Context ctx = (this.exposeAccessContext ? getJndiTemplate().getContext() : null);
try {

View File

@ -354,6 +354,7 @@ public class MBeanClientInterceptor
* @see #handleConnectFailure
*/
@Override
@Nullable
public Object invoke(MethodInvocation invocation) throws Throwable {
// Lazily connect to MBeanServer if necessary.
synchronized (this.preparationMonitor) {

View File

@ -192,6 +192,7 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
@Override
@Nullable
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
if (AopUtils.isToStringMethod(methodInvocation.getMethod())) {
return "JMS invoker proxy for queue [" + this.queue + "]";

View File

@ -420,8 +420,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
conHolder.setTimeoutInSeconds(timeoutToUse);
}
if (logger.isDebugEnabled()) {
logger.debug("Exposing JPA transaction as JDBC transaction [" +
conHolder.getConnectionHandle() + "]");
logger.debug("Exposing JPA transaction as JDBC transaction [" + conHandle + "]");
}
TransactionSynchronizationManager.bindResource(getDataSource(), conHolder);
txObject.setConnectionHolder(conHolder);
@ -601,8 +600,10 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
// Remove the JDBC connection holder from the thread, if exposed.
if (getDataSource() != null && txObject.hasConnectionHolder()) {
TransactionSynchronizationManager.unbindResource(getDataSource());
ConnectionHandle conHandle = txObject.getConnectionHolder().getConnectionHandle();
if (conHandle != null) {
try {
getJpaDialect().releaseJdbcConnection(txObject.getConnectionHolder().getConnectionHandle(),
getJpaDialect().releaseJdbcConnection(conHandle,
txObject.getEntityManagerHolder().getEntityManager());
}
catch (Exception ex) {
@ -610,6 +611,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
logger.error("Could not close JDBC connection after transaction", ex);
}
}
}
getJpaDialect().cleanupTransaction(txObject.getTransactionData());

View File

@ -27,6 +27,7 @@ import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.transaction.PlatformTransactionManager;
/**
@ -86,6 +87,7 @@ public class TransactionInterceptor extends TransactionAspectSupport implements
@Override
@Nullable
public Object invoke(final MethodInvocation invocation) throws Throwable {
// Work out the target class: may be {@code null}.
// The TransactionAttributeSource should be passed the target class

View File

@ -33,7 +33,6 @@ import org.apache.http.protocol.HttpContext;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.http.HttpMethod;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@ -51,7 +50,6 @@ import org.springframework.util.Assert;
public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsClientHttpRequestFactory
implements AsyncClientHttpRequestFactory, InitializingBean {
@Nullable
private HttpAsyncClient asyncClient;
@ -72,7 +70,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
*/
public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient) {
super();
setAsyncClient(asyncClient);
this.asyncClient = asyncClient;
}
/**
@ -82,7 +80,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
*/
public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyncClient) {
super();
setAsyncClient(asyncClient);
this.asyncClient = asyncClient;
}
/**
@ -94,7 +92,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
*/
public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, HttpAsyncClient asyncClient) {
super(httpClient);
setAsyncClient(asyncClient);
this.asyncClient = asyncClient;
}
/**
@ -107,7 +105,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
CloseableHttpClient httpClient, CloseableHttpAsyncClient asyncClient) {
super(httpClient);
setAsyncClient(asyncClient);
this.asyncClient = asyncClient;
}
@ -128,7 +126,6 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
* @since 4.3.10
* @see #getHttpClient()
*/
@Nullable
public HttpAsyncClient getAsyncClient() {
return this.asyncClient;
}
@ -150,7 +147,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
*/
@Deprecated
public CloseableHttpAsyncClient getHttpAsyncClient() {
Assert.state(this.asyncClient == null || this.asyncClient instanceof CloseableHttpAsyncClient,
Assert.state(this.asyncClient instanceof CloseableHttpAsyncClient,
"No CloseableHttpAsyncClient - use getAsyncClient() instead");
return (CloseableHttpAsyncClient) this.asyncClient;
}
@ -163,7 +160,6 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
private HttpAsyncClient startAsyncClient() {
HttpAsyncClient client = getAsyncClient();
Assert.state(client != null, "No HttpAsyncClient set");
if (client instanceof CloseableHttpAsyncClient) {
CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) client;
if (!closeableAsyncClient.isRunning()) {

View File

@ -59,7 +59,6 @@ import org.springframework.util.Assert;
*/
public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
@Nullable
private HttpClient httpClient;
@Nullable
@ -82,7 +81,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
* @param httpClient the HttpClient instance to use for this request factory
*/
public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) {
setHttpClient(httpClient);
this.httpClient = httpClient;
}
@ -99,7 +98,6 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
* Return the {@code HttpClient} used for
* {@linkplain #createRequest(URI, HttpMethod) synchronous execution}.
*/
@Nullable
public HttpClient getHttpClient() {
return this.httpClient;
}
@ -156,7 +154,6 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
HttpClient client = getHttpClient();
Assert.state(client != null, "No HttpClient set");
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
postProcessHttpRequest(httpRequest);

View File

@ -43,6 +43,7 @@ import org.springframework.util.MimeType;
*/
public class Jackson2JsonEncoder extends AbstractJackson2Encoder {
@Nullable
private final PrettyPrinter ssePrettyPrinter;

View File

@ -494,6 +494,7 @@ public class JaxWsPortClientInterceptor extends LocalJaxWsServiceFactory
@Override
@Nullable
public Object invoke(MethodInvocation invocation) throws Throwable {
if (AopUtils.isToStringMethod(invocation.getMethod())) {
return "JAX-WS proxy for port [" + getPortName() + "] of service [" + getServiceName() + "]";

View File

@ -753,6 +753,7 @@ public class MvcUriComponentsBuilder {
}
@Override
@Nullable
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable {
return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null);
}