From d0d0ff9890bec8d8f0c32962a46d9d9ec63300ca Mon Sep 17 00:00:00 2001 From: Nick Goupinets Date: Fri, 21 May 2021 12:00:01 -0400 Subject: [PATCH] Accounted for uninitialized fields --- .../java/ca/uhn/fhir/util/TerserUtil.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TerserUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TerserUtil.java index 157f6dd6ae2..5bd83d2bdc9 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TerserUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TerserUtil.java @@ -538,14 +538,14 @@ public final class TerserUtil { IBase newFieldValue = childDefinition.getChildByName(childDefinition.getElementName()).newInstance(); if (theFromFieldValue instanceof IPrimitiveType) { - try { - Method copyMethod = getMethod(theFromFieldValue, "copy"); - if (copyMethod != null) { - newFieldValue = (IBase) copyMethod.invoke(theFromFieldValue, new Object[]{}); - } - } catch (Throwable t) { - ((IPrimitiveType) newFieldValue).setValueAsString(((IPrimitiveType) theFromFieldValue).getValueAsString()); + try { + Method copyMethod = getMethod(theFromFieldValue, "copy"); + if (copyMethod != null) { + newFieldValue = (IBase) copyMethod.invoke(theFromFieldValue, new Object[]{}); } + } catch (Throwable t) { + ((IPrimitiveType) newFieldValue).setValueAsString(((IPrimitiveType) theFromFieldValue).getValueAsString()); + } } else { theTerser.cloneInto(theFromFieldValue, newFieldValue, true); } @@ -636,7 +636,11 @@ public final class TerserUtil { return; } - values.clear(); + try { + values.clear(); + } catch (Throwable t) { + ourLog.warn("Unable to clear values " + String.valueOf(values), t); + } } }