Skip to content

Commit 4e295a5

Browse files
jmarchionattojuan.marchionatto
andauthored
Issue 5418 support Boolean class return type in BaseInterceptorService (#5421)
* Enable child classes to use Boolean class return type * spotless --------- Co-authored-by: juan.marchionatto <[email protected]>
1 parent 7131be7 commit 4e295a5

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/executor/BaseInterceptorService.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,12 @@ public boolean hasHooks(POINTCUT thePointcut) {
263263
return myRegisteredPointcuts.contains(thePointcut);
264264
}
265265

266+
protected abstract Class<?> getBooleanReturnType();
267+
266268
@Override
267269
public boolean callHooks(POINTCUT thePointcut, HookParams theParams) {
268270
assert haveAppropriateParams(thePointcut, theParams);
269-
assert thePointcut.getReturnType() == void.class || thePointcut.getReturnType() == boolean.class;
271+
assert thePointcut.getReturnType() == void.class || thePointcut.getReturnType() == getBooleanReturnType();
270272

271273
Object retValObj = doCallHooks(thePointcut, theParams, true);
272274
return (Boolean) retValObj;
@@ -282,14 +284,14 @@ private Object doCallHooks(POINTCUT thePointcut, HookParams theParams, Object th
282284
for (BaseInvoker nextInvoker : invokers) {
283285
Object nextOutcome = nextInvoker.invoke(theParams);
284286
Class<?> pointcutReturnType = thePointcut.getReturnType();
285-
if (pointcutReturnType.equals(boolean.class)) {
287+
if (pointcutReturnType.equals(getBooleanReturnType())) {
286288
Boolean nextOutcomeAsBoolean = (Boolean) nextOutcome;
287289
if (Boolean.FALSE.equals(nextOutcomeAsBoolean)) {
288290
ourLog.trace("callHooks({}) for invoker({}) returned false", thePointcut, nextInvoker);
289291
theRetVal = false;
290292
break;
291293
}
292-
} else if (pointcutReturnType.equals(void.class) == false) {
294+
} else if (!pointcutReturnType.equals(void.class)) {
293295
if (nextOutcome != null) {
294296
theRetVal = nextOutcome;
295297
break;
@@ -349,7 +351,7 @@ private List<BaseInvoker> union(List<BaseInvoker>... theInvokersLists) {
349351

350352
List<BaseInvoker> retVal;
351353

352-
if (haveMultiple == false) {
354+
if (!haveMultiple) {
353355

354356
// The global list doesn't need to be sorted every time since it's sorted on
355357
// insertion each time. Doing so is a waste of cycles..
@@ -485,9 +487,9 @@ private HookInvoker(
485487
myMethod = theHookMethod;
486488

487489
Class<?> returnType = theHookMethod.getReturnType();
488-
if (myPointcut.getReturnType().equals(boolean.class)) {
490+
if (myPointcut.getReturnType().equals(getBooleanReturnType())) {
489491
Validate.isTrue(
490-
boolean.class.equals(returnType) || void.class.equals(returnType),
492+
getBooleanReturnType().equals(returnType) || void.class.equals(returnType),
491493
"Method does not return boolean or void: %s",
492494
theHookMethod);
493495
} else if (myPointcut.getReturnType().equals(void.class)) {

hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/executor/InterceptorService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public InterceptorService(String theName) {
5151
super(Pointcut.class, theName);
5252
}
5353

54+
@Override
55+
protected Class<?> getBooleanReturnType() {
56+
return boolean.class;
57+
}
58+
5459
@Override
5560
protected Optional<HookDescriptor> scanForHook(Method nextMethod) {
5661
return findAnnotation(nextMethod, Hook.class).map(t -> new HookDescriptor(t.value(), t.order()));

0 commit comments

Comments
 (0)