Make sure to return always a value for Boolean class return type. (#5424)
Implement change in a non-disruptive way for overriders Co-authored-by: juan.marchionatto <juan.marchionatto@smilecdr.com>
This commit is contained in:
parent
6b8f8a4ee6
commit
33ca4e9b99
|
@ -263,10 +263,14 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
|
|||
return myRegisteredPointcuts.contains(thePointcut);
|
||||
}
|
||||
|
||||
protected Class<?> getBooleanReturnType() {
|
||||
return boolean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callHooks(POINTCUT thePointcut, HookParams theParams) {
|
||||
assert haveAppropriateParams(thePointcut, theParams);
|
||||
assert thePointcut.getReturnType() == void.class || thePointcut.getReturnType() == boolean.class;
|
||||
assert thePointcut.getReturnType() == void.class || thePointcut.getReturnType() == getBooleanReturnType();
|
||||
|
||||
Object retValObj = doCallHooks(thePointcut, theParams, true);
|
||||
return (Boolean) retValObj;
|
||||
|
@ -282,14 +286,16 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
|
|||
for (BaseInvoker nextInvoker : invokers) {
|
||||
Object nextOutcome = nextInvoker.invoke(theParams);
|
||||
Class<?> pointcutReturnType = thePointcut.getReturnType();
|
||||
if (pointcutReturnType.equals(boolean.class)) {
|
||||
if (pointcutReturnType.equals(getBooleanReturnType())) {
|
||||
Boolean nextOutcomeAsBoolean = (Boolean) nextOutcome;
|
||||
if (Boolean.FALSE.equals(nextOutcomeAsBoolean)) {
|
||||
ourLog.trace("callHooks({}) for invoker({}) returned false", thePointcut, nextInvoker);
|
||||
theRetVal = false;
|
||||
break;
|
||||
} else {
|
||||
theRetVal = true;
|
||||
}
|
||||
} else if (pointcutReturnType.equals(void.class) == false) {
|
||||
} else if (!pointcutReturnType.equals(void.class)) {
|
||||
if (nextOutcome != null) {
|
||||
theRetVal = nextOutcome;
|
||||
break;
|
||||
|
@ -349,7 +355,7 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
|
|||
|
||||
List<BaseInvoker> retVal;
|
||||
|
||||
if (haveMultiple == false) {
|
||||
if (!haveMultiple) {
|
||||
|
||||
// The global list doesn't need to be sorted every time since it's sorted on
|
||||
// insertion each time. Doing so is a waste of cycles..
|
||||
|
@ -485,9 +491,9 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
|
|||
myMethod = theHookMethod;
|
||||
|
||||
Class<?> returnType = theHookMethod.getReturnType();
|
||||
if (myPointcut.getReturnType().equals(boolean.class)) {
|
||||
if (myPointcut.getReturnType().equals(getBooleanReturnType())) {
|
||||
Validate.isTrue(
|
||||
boolean.class.equals(returnType) || void.class.equals(returnType),
|
||||
getBooleanReturnType().equals(returnType) || void.class.equals(returnType),
|
||||
"Method does not return boolean or void: %s",
|
||||
theHookMethod);
|
||||
} else if (myPointcut.getReturnType().equals(void.class)) {
|
||||
|
|
Loading…
Reference in New Issue