From 428af56c82ba88fd9cd80af15c26080dddc9e8ed Mon Sep 17 00:00:00 2001 From: "b.debeaubien" Date: Fri, 21 Nov 2014 12:19:18 -0500 Subject: [PATCH] Fixed issue where empty narrative caused a StringIndexOutOfBoundsException Fixed encoding issue on XmlParserTest so it'll run in windows --- .../java/ca/uhn/fhir/model/primitive/XhtmlDt.java | 14 ++++++++------ .../java/ca/uhn/fhir/parser/XmlParserTest.java | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/XhtmlDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/XhtmlDt.java index 64070eae92e..e9dae4bbb0f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/XhtmlDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/XhtmlDt.java @@ -71,15 +71,17 @@ public class XhtmlDt extends BasePrimitive> { */ @Override public void setValueAsString(String theValue) throws DataFormatException { - String value = theValue.trim(); - if (value.charAt(0) != '<') { - value = "
" + value + "
"; + if (theValue == null || theValue.isEmpty()) { + super.setValueAsString(null); + } else { + String value = theValue.trim(); + if (value.charAt(0) != '<') { + value = "
" + value + "
"; + } + super.setValueAsString(value); } - - super.setValueAsString(value); } - public boolean hasContent() { return getValue() != null && getValue().size() > 0; } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java index f75d530c131..e9f1aba937d 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java @@ -89,7 +89,7 @@ public class XmlParserTest { @Test public void testProfileWithBoundCode() throws IOException { - String content = IOUtils.toString(XmlParserTest.class.getResourceAsStream("/DMIXAuditException.xml")); + String content = IOUtils.toString(XmlParserTest.class.getResourceAsStream("/DMIXAuditException.xml"), "UTF-8"); ourCtx.newXmlParser().parseResource(Profile.class, content); }