From aa16a46b7490df615f1d77a2f10ce38f15ca5c2c Mon Sep 17 00:00:00 2001 From: James Date: Tue, 23 Aug 2016 07:23:07 -0400 Subject: [PATCH] Fix #428 - Fix NPE when encoding extension --- .travis.yml | 2 +- .../main/java/ca/uhn/fhir/parser/BaseParser.java | 4 +++- .../src/main/java/ca/uhn/fhir/util/TestUtil.java | 16 ++++++++++++++++ src/changes/changes.xml | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2bdddfef6e6..048e6b014cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,4 +20,4 @@ before_script: script: # - mvn -e -B clean install && cd hapi-fhir-ra && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID clean test jacoco:report coveralls:report - - mvn -e -B -P ALLMODULES,NOPARALLEL clean install && cd hapi-fhir-jacoco && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID jacoco:report coveralls:report + - mvn -Dci=true -e -B -P ALLMODULES,NOPARALLEL clean install && cd hapi-fhir-jacoco && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID jacoco:report coveralls:report diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java index 17c00535a52..34781546014 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java @@ -1075,13 +1075,15 @@ public abstract class BaseParser implements IParser { StringBuilder b = new StringBuilder(); b.append(myResDef.getName()); return b; - } else { + } else if (myParent != null) { StringBuilder b = myParent.buildPath(); if (b != null && myDef != null) { b.append('.'); b.append(myDef.getElementName()); } return b; + } else { + return null; } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java index 369bc6f4a10..3820351322f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java @@ -26,7 +26,12 @@ import java.util.Arrays; import java.util.Locale; import java.util.TimeZone; +import org.slf4j.LoggerFactory; + import ca.uhn.fhir.context.FhirContext; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; public class TestUtil { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TestUtil.class); @@ -71,6 +76,7 @@ public class TestUtil { } } } + } /* @@ -94,6 +100,16 @@ public class TestUtil { String timeZone = availableTimeZones[(int)(Math.random() * availableTimeZones.length)]; TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); ourLog.info("Tests are using time zone: {}", TimeZone.getDefault().getID()); + + /* + * If we're running a CI build, set all loggers to TRACE level to ensure coverage + * on trace blocks + */ + if ("true".equals(System.getProperty("ci"))) { + for (Logger next : ((LoggerContext)LoggerFactory.getILoggerFactory()).getLoggerList()) { + next.setLevel(Level.TRACE); + } + } } diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 224a65892ef..4053ff5d039 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -192,6 +192,10 @@ required in earlier versions of FHIR but has been removed from the specification. + + Fix NullPointerException when encoding an extension containing CodeableConcept + with log level set to TRACE. Thanks to Bill Denton for the report! +