Explicit nullability declarations for all AOP Alliance methods
Includes consistent declarations in AOP Alliance related Spring AOP code. Closes gh-24117
This commit is contained in:
@@ -361,6 +361,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
* @return the result of the invocation
|
||||
* @see CacheOperationInvoker#invoke()
|
||||
*/
|
||||
@Nullable
|
||||
protected Object invokeOperation(CacheOperationInvoker invoker) {
|
||||
return invoker.invoke();
|
||||
}
|
||||
@@ -445,7 +446,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Object unwrapReturnValue(Object returnValue) {
|
||||
private Object unwrapReturnValue(@Nullable Object returnValue) {
|
||||
return ObjectUtils.unwrapOptional(returnValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -23,6 +23,7 @@ import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* AOP Alliance MethodInterceptor for declarative cache
|
||||
@@ -57,8 +58,10 @@ public class CacheInterceptor extends CacheAspectSupport implements MethodInterc
|
||||
}
|
||||
};
|
||||
|
||||
Object target = invocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
try {
|
||||
return execute(aopAllianceInvoker, invocation.getThis(), method, invocation.getArguments());
|
||||
return execute(aopAllianceInvoker, target, method, invocation.getArguments());
|
||||
}
|
||||
catch (CacheOperationInvoker.ThrowableWrapper th) {
|
||||
throw th.getOriginal();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cache.interceptor;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract the invocation of a cache operation.
|
||||
*
|
||||
@@ -36,6 +38,7 @@ public interface CacheOperationInvoker {
|
||||
* @return the result of the operation
|
||||
* @throws ThrowableWrapper if an error occurred while invoking the operation
|
||||
*/
|
||||
@Nullable
|
||||
Object invoke() throws ThrowableWrapper;
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -94,6 +94,7 @@ public class EventPublicationInterceptor
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Object retVal = invocation.proceed();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -368,6 +368,7 @@ public class JndiObjectFactoryBean extends JndiObjectLocator
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Context ctx = (isEligible(invocation.getMethod()) ? this.jndiTemplate.getContext() : null);
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -268,6 +268,7 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho
|
||||
* @see java.rmi.NoSuchObjectException
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Object stub;
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -255,6 +255,7 @@ public class RmiClientInterceptor extends RemoteInvocationBasedAccessor
|
||||
* @see java.rmi.NoSuchObjectException
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Remote stub = getStub();
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -18,6 +18,8 @@ package org.springframework.remoting.support;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract base class for remote service accessors that are based
|
||||
* on serialization of {@link RemoteInvocation} objects.
|
||||
@@ -81,6 +83,7 @@ public abstract class RemoteInvocationBasedAccessor extends UrlBasedRemoteAccess
|
||||
* @throws Throwable if the invocation result is an exception
|
||||
* @see RemoteInvocationResult#recreate()
|
||||
*/
|
||||
@Nullable
|
||||
protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable {
|
||||
return result.recreate();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -23,6 +23,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -68,6 +69,7 @@ public class RemoteInvocationTraceInterceptor implements MethodInterceptor {
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Method method = invocation.getMethod();
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
@@ -33,6 +33,8 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.SmartFactoryBean;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -87,7 +89,7 @@ public class MethodValidationInterceptor implements MethodInterceptor {
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
// Avoid Validator invocation on FactoryBean.getObjectType/isSingleton
|
||||
if (isFactoryBeanMetadataMethod(invocation.getMethod())) {
|
||||
@@ -101,17 +103,18 @@ public class MethodValidationInterceptor implements MethodInterceptor {
|
||||
Method methodToValidate = invocation.getMethod();
|
||||
Set<ConstraintViolation<Object>> result;
|
||||
|
||||
Object target = invocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
|
||||
try {
|
||||
result = execVal.validateParameters(
|
||||
invocation.getThis(), methodToValidate, invocation.getArguments(), groups);
|
||||
result = execVal.validateParameters(target, methodToValidate, invocation.getArguments(), groups);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// Probably a generic type mismatch between interface and impl as reported in SPR-12237 / HV-1011
|
||||
// Let's try to find the bridged method on the implementation class...
|
||||
methodToValidate = BridgeMethodResolver.findBridgedMethod(
|
||||
ClassUtils.getMostSpecificMethod(invocation.getMethod(), invocation.getThis().getClass()));
|
||||
result = execVal.validateParameters(
|
||||
invocation.getThis(), methodToValidate, invocation.getArguments(), groups);
|
||||
ClassUtils.getMostSpecificMethod(invocation.getMethod(), target.getClass()));
|
||||
result = execVal.validateParameters(target, methodToValidate, invocation.getArguments(), groups);
|
||||
}
|
||||
if (!result.isEmpty()) {
|
||||
throw new ConstraintViolationException(result);
|
||||
@@ -119,7 +122,7 @@ public class MethodValidationInterceptor implements MethodInterceptor {
|
||||
|
||||
Object returnValue = invocation.proceed();
|
||||
|
||||
result = execVal.validateReturnValue(invocation.getThis(), methodToValidate, returnValue, groups);
|
||||
result = execVal.validateReturnValue(target, methodToValidate, returnValue, groups);
|
||||
if (!result.isEmpty()) {
|
||||
throw new ConstraintViolationException(result);
|
||||
}
|
||||
@@ -158,7 +161,9 @@ public class MethodValidationInterceptor implements MethodInterceptor {
|
||||
protected Class<?>[] determineValidationGroups(MethodInvocation invocation) {
|
||||
Validated validatedAnn = AnnotationUtils.findAnnotation(invocation.getMethod(), Validated.class);
|
||||
if (validatedAnn == null) {
|
||||
validatedAnn = AnnotationUtils.findAnnotation(invocation.getThis().getClass(), Validated.class);
|
||||
Object target = invocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
validatedAnn = AnnotationUtils.findAnnotation(target.getClass(), Validated.class);
|
||||
}
|
||||
return (validatedAnn != null ? validatedAnn.value() : new Class<?>[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user