From e2f03a9a26cc1375c30b30d1384ea290520e8e91 Mon Sep 17 00:00:00 2001 From: FilipDomazet Date: Fri, 16 Sep 2016 21:02:22 +0200 Subject: [PATCH] Fixed issue with adding profile information to an unmodifiable list (#448) --- .../main/java/ca/uhn/fhir/parser/ParserState.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java index 42ce4a4677a..1cc7ed4fbdb 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java @@ -25,6 +25,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotEmpty; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -1870,13 +1871,17 @@ class ParserState { } else if (theLocalPart.equals("profile")) { @SuppressWarnings("unchecked") List profiles = (List) myMap.get(ResourceMetadataKeyEnum.PROFILES); - if (profiles == null) { - profiles = new ArrayList(); - myMap.put(ResourceMetadataKeyEnum.PROFILES, profiles); + List newProfiles; + if (profiles != null) { + newProfiles = new ArrayList(profiles.size() + 1); + newProfiles.addAll(profiles); + } else { + newProfiles = new ArrayList(1); } IdDt profile = new IdDt(); push(new PrimitiveState(getPreResourceState(), profile)); - profiles.add(profile); + newProfiles.add(profile); + myMap.put(ResourceMetadataKeyEnum.PROFILES, Collections.unmodifiableList(newProfiles)); } else if (theLocalPart.equals("tag")) { TagList tagList = (TagList) myMap.get(ResourceMetadataKeyEnum.TAG_LIST); if (tagList == null) {