From 6021a09288516a056395242217129dd951543d4b Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 13 Sep 2022 16:25:15 -0400 Subject: [PATCH] Avoid NPE when run in IJ (#4018) * Avoid NPE when run in IJ * Add changelog --- .../hapi/fhir/changelog/6_2_0/4018-avoid-npe-in-ij.yaml | 4 ++++ .../ca/uhn/fhir/rest/server/method/BaseMethodBinding.java | 2 +- .../fhir/rest/server/method/ConditionalParamBinder.java | 7 ++----- .../java/ca/uhn/fhir/rest/server/method/MethodUtil.java | 4 ++-- .../fhir/rest/server/method/OperationMethodBinding.java | 1 + 5 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4018-avoid-npe-in-ij.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4018-avoid-npe-in-ij.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4018-avoid-npe-in-ij.yaml new file mode 100644 index 00000000000..99772c3be04 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4018-avoid-npe-in-ij.yaml @@ -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." diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java index d9d9a05b664..61626218070 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java @@ -76,7 +76,7 @@ public abstract class BaseMethodBinding { myMethod = theMethod; myContext = theContext; myProvider = theProvider; - myParameters = MethodUtil.getResourceParameters(theContext, theMethod, theProvider, getRestOperationType()); + myParameters = MethodUtil.getResourceParameters(theContext, theMethod, theProvider); myQueryParameters = myParameters .stream() .filter(t -> t instanceof BaseQueryParameter) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConditionalParamBinder.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConditionalParamBinder.java index 87b0a5e1c5d..15d85b7c54a 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConditionalParamBinder.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConditionalParamBinder.java @@ -35,12 +35,9 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; class ConditionalParamBinder implements IParameter { - private RestOperationTypeEnum myOperationType; private boolean mySupportsMultiple; - ConditionalParamBinder(RestOperationTypeEnum theOperationType, boolean theSupportsMultiple) { - Validate.notNull(theOperationType, "theOperationType can not be null"); - myOperationType = theOperationType; + ConditionalParamBinder(boolean theSupportsMultiple) { mySupportsMultiple = theSupportsMultiple; } @@ -57,7 +54,7 @@ class ConditionalParamBinder implements IParameter { @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { - return theRequest.getConditionalUrl(myOperationType); + return theRequest.getConditionalUrl(theMethodBinding.getRestOperationType()); } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtil.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtil.java index 515f8677f7a..5f6f6f77df0 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtil.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtil.java @@ -72,7 +72,7 @@ public class MethodUtil { @SuppressWarnings("unchecked") - public static List getResourceParameters(final FhirContext theContext, Method theMethod, Object theProvider, RestOperationTypeEnum theRestfulOperationTypeEnum) { + public static List getResourceParameters(final FhirContext theContext, Method theMethod, Object theProvider) { List parameters = new ArrayList<>(); Class[] parameterTypes = theMethod.getParameterTypes(); @@ -240,7 +240,7 @@ public class MethodUtil { } else if (nextAnnotation instanceof TransactionParam) { param = new TransactionParameter(theContext); } else if (nextAnnotation instanceof ConditionalUrlParam) { - param = new ConditionalParamBinder(theRestfulOperationTypeEnum, ((ConditionalUrlParam) nextAnnotation).supportsMultiple()); + param = new ConditionalParamBinder(((ConditionalUrlParam) nextAnnotation).supportsMultiple()); } else if (nextAnnotation instanceof OperationParam) { Operation op = theMethod.getAnnotation(Operation.class); if (op == null) { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/OperationMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/OperationMethodBinding.java index cc1e7271183..1f01aa60890 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/OperationMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/OperationMethodBinding.java @@ -222,6 +222,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { @Nonnull @Override public RestOperationTypeEnum getRestOperationType() { + assert myOtherOperationType != null; return myOtherOperationType; }