Avoid NPE when run in IJ (#4018)

* Avoid NPE when run in IJ

* Add changelog
This commit is contained in:
James Agnew 2022-09-13 16:25:15 -04:00 committed by GitHub
parent ad57ebf148
commit 6021a09288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 8 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 4018
title: "When running HAPI FHIR inside intellij with runtime Nonnull assertions enabled, a sequencing issue in OperationMethodBinding could cause a null pointer exception. This has been corrected."

View File

@ -76,7 +76,7 @@ public abstract class BaseMethodBinding<T> {
myMethod = theMethod; myMethod = theMethod;
myContext = theContext; myContext = theContext;
myProvider = theProvider; myProvider = theProvider;
myParameters = MethodUtil.getResourceParameters(theContext, theMethod, theProvider, getRestOperationType()); myParameters = MethodUtil.getResourceParameters(theContext, theMethod, theProvider);
myQueryParameters = myParameters myQueryParameters = myParameters
.stream() .stream()
.filter(t -> t instanceof BaseQueryParameter) .filter(t -> t instanceof BaseQueryParameter)

View File

@ -35,12 +35,9 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
class ConditionalParamBinder implements IParameter { class ConditionalParamBinder implements IParameter {
private RestOperationTypeEnum myOperationType;
private boolean mySupportsMultiple; private boolean mySupportsMultiple;
ConditionalParamBinder(RestOperationTypeEnum theOperationType, boolean theSupportsMultiple) { ConditionalParamBinder(boolean theSupportsMultiple) {
Validate.notNull(theOperationType, "theOperationType can not be null");
myOperationType = theOperationType;
mySupportsMultiple = theSupportsMultiple; mySupportsMultiple = theSupportsMultiple;
} }
@ -57,7 +54,7 @@ class ConditionalParamBinder implements IParameter {
@Override @Override
public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding<?> theMethodBinding) throws InternalErrorException, InvalidRequestException { public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding<?> theMethodBinding) throws InternalErrorException, InvalidRequestException {
return theRequest.getConditionalUrl(myOperationType); return theRequest.getConditionalUrl(theMethodBinding.getRestOperationType());
} }
} }

View File

@ -72,7 +72,7 @@ public class MethodUtil {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static List<IParameter> getResourceParameters(final FhirContext theContext, Method theMethod, Object theProvider, RestOperationTypeEnum theRestfulOperationTypeEnum) { public static List<IParameter> getResourceParameters(final FhirContext theContext, Method theMethod, Object theProvider) {
List<IParameter> parameters = new ArrayList<>(); List<IParameter> parameters = new ArrayList<>();
Class<?>[] parameterTypes = theMethod.getParameterTypes(); Class<?>[] parameterTypes = theMethod.getParameterTypes();
@ -240,7 +240,7 @@ public class MethodUtil {
} else if (nextAnnotation instanceof TransactionParam) { } else if (nextAnnotation instanceof TransactionParam) {
param = new TransactionParameter(theContext); param = new TransactionParameter(theContext);
} else if (nextAnnotation instanceof ConditionalUrlParam) { } else if (nextAnnotation instanceof ConditionalUrlParam) {
param = new ConditionalParamBinder(theRestfulOperationTypeEnum, ((ConditionalUrlParam) nextAnnotation).supportsMultiple()); param = new ConditionalParamBinder(((ConditionalUrlParam) nextAnnotation).supportsMultiple());
} else if (nextAnnotation instanceof OperationParam) { } else if (nextAnnotation instanceof OperationParam) {
Operation op = theMethod.getAnnotation(Operation.class); Operation op = theMethod.getAnnotation(Operation.class);
if (op == null) { if (op == null) {

View File

@ -222,6 +222,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
@Nonnull @Nonnull
@Override @Override
public RestOperationTypeEnum getRestOperationType() { public RestOperationTypeEnum getRestOperationType() {
assert myOtherOperationType != null;
return myOtherOperationType; return myOtherOperationType;
} }