# 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:

{% code overflow="wrap" %}

```
[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)
```

{% endcode %}

## 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**:

```json
{"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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/troubleshooting-faq/java/typenotpresentexception-error-when-running-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
