> For the complete documentation index, see [llms.txt](https://docs.sealights.io/knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealights.io/knowledgebase/setup-and-configuration/troubleshooting-faq/java/typenotpresentexception-error-when-running-tests.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
