TypeNotPresentException Error When Running Tests
Problem
SeaLights Java Test Listener (in its test runner role) reports Failed instrument for code coverage
on specific test classes due to a TypeNotPresentException
.
This issue is commonly seen when running tests under TestNG, where SeaLights attempts to instrument test classes for coverage but fails because some referenced types are missing from the runtime classpath.
Here is an example log output you may see:
[SEALIGHTS] 2025-06-27 09:08:29,258 INFO [130|main |001] i.s.o.a.e.AgentEventsController : Failed instrument for code coverage class 'com/example/transfers/withdrawals/Card/datadriven/WithdrawalsDataDrivenBMWIT',exception at class io.sealights.onpremise.agents.testlistener.codecoverage.CustomerClassTransformer : java.lang.TypeNotPresentException: Type com/example/api/platform/transfers/v3/model/WithdrawalResponse not presentat io.sealights.dependencies.org.objectweb.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1045)at io.sealights.onpremise.agents.commons.instrument.annotations.UpsertClassAnnotationTransformer$1.getCommonSuperClass(UpsertClassAnnotationTransformer.java:85)
Root Cause
During bytecode instrumentation, ASM’s ClassWriter
created with the COMPUTE_FRAMES
flag may attempt to resolve the common super class of the instrumented and target classes. If a referenced type is not loadable on the current classpath (e.g., shaded/optional/missing at test runtime), ASM throws TypeNotPresentException
, and SeaLights skips instrumentation of that class.
Resolution
Configure the SeaLights Test Listener to use a simpler ClassWriter mode that skips frame computation. Add the following to the JSON configuration used by your Maven or Gradle SeaLights plugin:
{"sealightsJvmParams": {"sl.featuresData.testNgClassWriterFlag": "0"}}
This disables COMPUTE_FRAMES
and prevents ASM from resolving missing supertypes. It only affects instrumentation within the listener and does not change your compiled artifacts. As an alternative, you can fix the classpath so all referenced types are available, but this flag is a quick, low‑risk workaround.
After applying, re‑run your tests and confirm the error disappears and coverage is reported for the affected classes.
Last updated
Was this helpful?