hapi-fhir: Class too large: org/hl7/fhir/r5/formats/JsonParser

Describe the bug We’re using JaCoCO to measure code coverage. In one of our unit tests, JaCoCo is printing the following stacktrace:

java.lang.instrument.IllegalClassFormatException: Error while instrumenting org/hl7/fhir/r5/formats/XmlParser.
        at org.jacoco.agent.rt.internal_3570298.CoverageTransformer.transform(CoverageTransformer.java:94)
        at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at org.hl7.fhir.validation.instance.InstanceValidator.validateResource(InstanceValidator.java:5239)
        at org.hl7.fhir.validation.instance.InstanceValidator.validate(InstanceValidator.java:745)
        at org.hl7.fhir.validation.instance.InstanceValidator.validate(InstanceValidator.java:593)
        at org.hl7.fhir.common.hapi.validation.validator.ValidatorWrapper.validate(ValidatorWrapper.java:158)
        at org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator.validate(FhirInstanceValidator.java:235)
        at org.hl7.fhir.common.hapi.validation.validator.BaseValidatorBridge.doValidate(BaseValidatorBridge.java:22)
        at org.hl7.fhir.common.hapi.validation.validator.BaseValidatorBridge.validateResource(BaseValidatorBridge.java:45)
        at org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator.validateResource(FhirInstanceValidator.java:25)
        at ca.uhn.fhir.validation.FhirValidator.validateWithResult(FhirValidator.java:221)
        at ca.uhn.fhir.validation.FhirValidator.validateWithResult(FhirValidator.java:191)

Then another stacktrace, this time for JsonParser.

This is what the test does:

@Test
void test() {
	FhirContext context = FhirContext.forR4();
	FhirValidator validator = context.newValidator();

	ValidationSupportChain validationSupportChain = new ValidationSupportChain(new DefaultProfileValidationSupport(context),
			new CommonCodeSystemsTerminologyService(context), new InMemoryTerminologyServerValidationSupport(context),
			new SnapshotGeneratingValidationSupport(context));
	CachingValidationSupport validationSupport = new CachingValidationSupport(validationSupportChain);
	validator.registerValidatorModule(new FhirInstanceValidator(validationSupport));

	AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
	allergyIntolerance.setId("1");
	allergyIntolerance.setRecorder(new Reference(new Practitioner().setId("1")));

	ValidationResult validationResult = validator.validateWithResult(allergyIntolerance);
	Assertions.assertFalse(validationResult.isSuccessful(), validationResult.toString());

}

Our actual test is using NpmPackageValidationSupport as described here.

It seems that the org.hl7.fhir.r5.formats.JsonParser and org.hl7.fhir.r5.formats.XmlParser classes are too big to be instrumented by JaCoCo. Note that those classes belong to the R5 version while our test is only using R4. The R5 version seems to be instantiated from the ourR5Context static field of VersionSpecificWorkerContextWrapper.

To Reproduce I have created a small project recreating the issue :

  1. git clone https://github.com/Athou/hapi-jacoco-error.git
  2. mvn test

Expected behavior The test should pass without errors printed in the console.

Environment (please complete the following information):

  • HAPI FHIR Version 5.6.1
  • OS: Windows

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 16

Commits related to this issue

Most upvoted comments

This should be fixed now