hapifhir / org.hl7.fhir.core

Apache License 2.0
151 stars 151 forks source link

Class too large: org/hl7/fhir/r4/formats/JsonParser #1688

Closed eldcn closed 2 weeks ago

eldcn commented 1 month ago

We are using org.hl7.fhir.r4 dependency in our project, and we are facing an issue with Jacoco when generating the coverage report:

> Failed to transform org.hl7.fhir.r4-6.0.22.jar (ca.uhn.hapi.fhir:org.hl7.fhir.r4:6.0.22) to match attributes {artifactType=android-dex, dexing-component-attributes=ComponentSpecificParameters(minSdkVersion=31, debuggable=true, enableCoreLibraryDesugaring=false, enableGlobalSynthetics=true, enableApiModeling=false, dependenciesClassesAreInstrumented=false, asmTransformComponent=null, useJacocoTransformInstrumentation=true, enableDesugaring=true, needsClasspath=false, useFullClasspath=false, componentIfUsingFullClasspath=null), org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for JacocoTransform: gradle/caches/modules-2/files-2.1/ca.uhn.hapi.fhir/org.hl7.fhir.r4/6.0.22/b483195bff8564caf6134f5c8556d5148019ee8f/org.hl7.fhir.r4-6.0.22.jar.

Caused by: org.objectweb.asm.ClassTooLargeException: Class too large: org/hl7/fhir/r4/formats/JsonParser
    at org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:622)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:92)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:109)
    ... 119 more

I saw this related issue here: https://github.com/hapifhir/hapi-fhir/issues/3268. Excluding the file from Jacoco configuration does not help. Any hints to overcome the issue are more then welcome. Thank you!

grahamegrieve commented 1 month ago

but this doesn't stop you getting a coverage report, right?

eldcn commented 1 month ago

@grahamegrieve Unfortunately the whole task fails. It is getting executed during connectedCheck gradle task via mergeExtDexDebug. I noticed that hapi-fhir is using a new component for parsing: https://github.com/hapifhir/hapi-fhir/blob/master/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java. Would it be an option to extract the formaters in a separate module so that clients not using it can manually exclude?

jamesagnew commented 1 month ago

FWIW I don't know what's causing this issue, but we run JaCoCo on the hapi-fhir build too and it doesn't fail with this issue even though it obviously also links against that same JAR... So there is definitely something we're doing differently. Not sure what it could be though.

Might be worth looking at how jacoco is set up in the hapi-fhir build to see if you see any differences in terms of versions and flags and whatnot.

grahamegrieve commented 1 month ago

the hapi is not a new parser - both parsers have existed for many years, and have different purposes, and neither are going away. But Jacoco shouldn't fail outright... take it up with them.