# ClassNotFoundException : com.fasterxml.jackson.core.type.TypeReference

**URL:** <https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793>\
**Category:** APM\
**Tags:** java\
**Created:** [January 19, 2022, 9:58am UTC](https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793 "2022-01-19T09:58:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sadu](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sadu](https://discuss.elastic.co/u/sadu)\
**Post date:** [January 19, 2022, 9:58am UTC](https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793/1 "2022-01-19T09:58:48Z")

</div>

**APM Server version** :  
1.28.4

\*\* Attaching APM agent \*\*:  
By VM option:  
-javaagent:lib/elastic-apm-agent.jar

\*\* Java \*\*:  
1.8

Hello,

In our application we create view where admin can check current APM agent configuration. Admin can easy change for example configuration for sanitize\_field\_names property.

We show all available properties. To achieve this we use reflection. We use `ElasticApmTracer.getConfigurationRegistry()` which return `ConfigurationRegistry` object from Stagemonitor library.

This view stop working after move APM agent to isolated class loader.

> <https://github.com/elastic/apm-agent-java/pull/2109>
>
> \## What does this PR do?
> \<!--
> Replace this comment with a description of what'…s being changed by this PR.
> Please explain the WHAT: A clear and concise description of what (patterns used, algorithms implemented, design architecture, message processing, etc.)
> Can be as simple as Fixes elastic/apm-agent-java#123 if there's a corresponding issue.
> \--\>
> 
> \* Closes elastic/apm-agent-java#1338
> \* Closes elastic/apm-agent-java#1339
> \* Closes elastic/apm-agent-java#961
> 
> \## Module changes
> 
> \* Renames \`elastic-apm-agent\` to \`apm-agent\`.
> \* This module doesn't contain \`Premain-Class\`/\`Agent-Class\` manifest entries (it cannot be used via \`-javaagent\`)
> \* It gets published to maven central for the sole purpose of making it easier to debug the agent.
> \* This module contains the bulk of the agent, including the core and all instrumentation plugins.
> \* Because this module will be loaded from an isolated class loader hierarchy, we don't need to shade/relocate dependencies anymore.
> \* Renames \`apm-agent-premain\` to \`elastic-apm-agent\`.
> \* This one does have \`Premain-Class\`/\`Agent-Class\` manifest entries.
> \* This module contains just a minimal set of classes that are needed for bootstrapping the agent
> \* It contains the classes from \`apm-agent\` as shaded resource in the \`agent\` folder.
> \* All \`.class\` files are renamed to \`.esclass\` so that they can't be loaded by regular class loaders
> \* It creates an \`ShadedClassLoader\`, aka the agent class loader, which can load the \`.esclass\` files.
> \* This makes all the agent classes, besides \`java.lang.IndyBootstrapDispatcher\` invisible to the regular class loader hierarchy.
> \* This ensures that there can be no conflicts with equally named classes in regular class loader hierarchy, so shading/relocating is not necessary anymore.
> \* Also, class path scanning tools don't get slowed down or trip over agent classes.
> \* In addition, this provides a better solution for the OSGi problem (or similar filtering class loaders) that doesn't rely on instrumenting all class loaders and \`sun.misc.Unsafe\`-based injection (\`InjectionStrategy.UsingUnsafe\`/ \`InjectionStrategy.UsingReflection\`).
> \* Adds a new \`apm-agent-common\` module.
> \* Contains classes that are needed ~during agent startup~, in the agent itself, and in the attacher module
> \* One example is the \`ResourceExtractionUtil\` that extracts a class path resource to the temp dir, adds a md5 hash and re-uses already extracted resources if the hashes match.
> 
> This is how the new structure looks like in detail:
> \<img width="338" alt="Screen Shot 2021-09-10 at 14 57 22" src="https://user-images.githubusercontent.com/2163464/132856656-94dda100-30b5-46c3-8e0b-d9dcb14b59a0.png"\>
> 
> 
> 
> More details about the indy-dispatching approach can be found in the Javadocs of \[\`IndyBootstrap\`\](https://github.com/elastic/apm-agent-java/blob/master/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/IndyBootstrap.java)
> 
> \## Checklist
> \<!--
> You only have to fill one category of checkboxes, depending on the type of the PR.
> Please DO NOT remove any item, ~~striking through~~ those that do not apply.
> Just ignore the checkboxes of categories that don't apply.
> \--\>
> 
> 
> \- \[x\] This is something else
> - \[x\] I have updated \[CHANGELOG.asciidoc\](https://github.com/elastic/apm-agent-java/blob/master/CHANGELOG.asciidoc)

Of course our view broke down. Application class loader can not find class from APM.

I try to figured out how to fix this view. For some internal reason we maintain own APM agent with custom changes. For test I simply add to `co.elastic.apm.agent.premain.AgentMain`

```auto
public static URLClassLoader getAgentClassLoader() {
        return agentClassLoader;
}

```

I use this dirty "hack" in our application with reflection and APM class loader. For example:

```auto
 var clazz = Class.forName("co.elastic.apm.agent.impl.ElasticApmTracer", false, AgentMain.getAgentClassLoader)

```

When I call (by reflection) code from `ConfigurationRegistry.getConfigurationOptionsByKey()` which return `ConfigurationOption` object I get exception:

ClassNotFoundException : com.fasterxml.jackson.core.type.TypeReference

`ConfigurationOption` from Stagemonitor has dependency to jackson library and `ConfigurationOption` import some packages from that library. Exception occure because there is no jackson class in class patch. I check original APM jar "apm-agent-attach-1.28.4.jar" from maven repo. In patch "agent/com" I can't find classes from jackson lib.

This is expected behavior ? How class `ElasticApmAgent` use `ConfigurationOption` without this class on class patch ?

I'm aware that reflection and custom changes can be problematic, error can back in any agent update and is not good practice.

Thank you

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [January 19, 2022, 2:44pm UTC](https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793/2 "2022-01-19T14:44:39Z")

</div>

> [@sadu](#):
>
> In our application we create view where admin can check current APM agent configuration. Admin can easy change for example configuration for sanitize\_field\_names property.

Why aren't you using the [central configuration](https://www.elastic.co/guide/en/kibana/current/agent-configuration.html) feature in Kibana?

As you mentioned, you're pretty deep in unsupported territory. But it could help to see the full stack trace. Normally, the `ConfigurationOption` should get linked lazily so that unless you're invoking `org.stagemonitor.configuration.ConfigurationOption#jsonOption`, the missing type doesn't cause an issue. Maybe you're calling `ConfigurationOption.class.getMethods()` or similar which causes the Jackson classes to be linked?

> [@sadu](#):
>
> For some internal reason we maintain own APM agent with custom changes.

You might be interested in [external plugins](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-plugins-dir)

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [January 19, 2022, 3:02pm UTC](https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793/3 "2022-01-19T15:02:27Z")

</div>

Hi @sadu !

Most of the agent is now loaded in a separate classloader that is not accessible from the application, this is intentional and now part of the agent architecture as it provides many benefits:

- avoids having agent classes visible from the application, which helps to prevent side-effects when runtime classpath-scanning is used.
- avoids requirement to shade agent classes and dependencies (simpler packaging and debugging)

Before this change the agent was accessible directly from the application, but it was an implementation detail, and it was never meant to be a supported way to handle configuration.

However, one better and simpler alternative would be to store configuration in a properties file (external to the application, not in classpath resources) then allow modifications to this file through your application.

---

<div class="post-metadata">

**Author:** ![sadu](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sadu](https://discuss.elastic.co/u/sadu)\
**Post date:** [January 25, 2022, 11:22am UTC](https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793/4 "2022-01-25T11:22:36Z")

</div>

> [@felixbarny](#):
>
> Why aren't you using the [central configuration](https://www.elastic.co/guide/en/kibana/current/agent-configuration.html) feature in Kibana?

Not all options can be change from this view.

> [@felixbarny](#):
>
> Maybe you're calling `ConfigurationOption.class.getMethods()` or similar which causes the Jackson classes to be linked?

Yes I call ConfigurationOption.class.getMethods() to invoke for example "getKey" or "valueAsString".

So, this is expected behavior. Add jackson to classpatch in our own plugin solves problem, but maybe you have a better idea ?

---

<div class="post-metadata">

**Author:** ![sadu](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sadu](https://discuss.elastic.co/u/sadu)\
**Post date:** [January 25, 2022, 11:33am UTC](https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793/5 "2022-01-25T11:33:27Z")

</div>

> [@Sylvain\_Juge](#):
>
> However, one better and simpler alternative would be to store configuration in a properties file (external to the application, not in classpath resources) then allow modifications to this file through your application.

This is what we do, but we want to show user all possible properties that could be set/change. That's why we need all possible keys. When user set something we save this to external properties file.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [January 26, 2022, 9:57am UTC](https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793/6 "2022-01-26T09:57:03Z")

</div>

> [@sadu](#):
>
> Yes I call ConfigurationOption.class.getMethods() to invoke for example "getKey" or "valueAsString".

Use [`Class::getMethod`](https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getMethod-java.lang.String-java.lang.Class...-) instead.

---

<div class="post-metadata">

**Author:** ![sadu](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sadu](https://discuss.elastic.co/u/sadu)\
**Post date:** [February 3, 2022, 10:56am UTC](https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793/7 "2022-02-03T10:56:26Z")

</div>

Hi @felixbarny ,  
Thank for tip. I'm afraid I can't do that, because I can't access the definition of APM class and use method reference operator like you suggest. I can use only reflection.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 24, 2022, 6:57am UTC](https://discuss.elastic.co/t/classnotfoundexception-com-fasterxml-jackson-core-type-typereference/294793/8 "2022-02-24T06:57:12Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
