# JVM crashes with APM agent 1.33 and JPMS enabled

**URL:** <https://discuss.elastic.co/t/jvm-crashes-with-apm-agent-1-33-and-jpms-enabled/309503>\
**Category:** APM\
**Tags:** java\
**Created:** [July 13, 2022, 7:54am UTC](https://discuss.elastic.co/t/jvm-crashes-with-apm-agent-1-33-and-jpms-enabled/309503 "2022-07-13T07:54:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmettl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emmettl/32/108237_2.png) [@emmettl](https://discuss.elastic.co/u/emmettl)\
**Post date:** [July 13, 2022, 7:54am UTC](https://discuss.elastic.co/t/jvm-crashes-with-apm-agent-1-33-and-jpms-enabled/309503/1 "2022-07-13T07:54:58Z")

</div>

**Kibana version** : 7.17.4

**Elasticsearch version** : 7.17.4

**APM Server version** : 7.17.4

**APM Agent language and version** : 1.33.0

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**: Agent is attached via -javaagent arg.  
Application is based on spring boot 2.7.1 (with log4j config defined).  
APM agent is using defaults (no explicit config defined for logging etc).  
Environment is Linux OpenJDK 64-Bit Server VM Temurin-17.0.3+7,  
JVM exits after about 2 seconds from startup, with the following exception logged to STDOUT.

```auto
java.lang.NullPointerException: Cannot invoke "co.elastic.apm.agent.log4j2.reformatting.Log4J2EcsReformattingHelper.getEcsOverridingFormatterFor(Object)" because "co.elastic.apm.agent.log4j2.reformatting.Log4j2AppenderGetLayoutAdvice.helper" is null
        at co.elastic.apm.agent.log4j2.reformatting.Log4j2AppenderGetLayoutAdvice.reformatLoggingEvent(Log4j2AppenderGetLayoutAdvice.java:50)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.appender.AbstractAppender.getLayout(AbstractAppender.java:264)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.start(AbstractOutputStreamAppender.java:163)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:311)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
        at org.apache.logging.log4j@2.17.2/org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
        at org.apache.logging.log4j@2.17.2/org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:137)
        at co.elastic.apm.agent.logging.Log4jLoggerFactoryBridge.getContext(Log4jLoggerFactoryBridge.java:64)
        at org.apache.logging.log4j@2.17.2/org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
        at co.elastic.apm.agent.logging.Log4jLoggerFactoryBridge.getLogger(Log4jLoggerFactoryBridge.java:37)
        at co.elastic.apm.agent.sdk.logging.LoggerFactory$1.run(LoggerFactory.java:68)
        at co.elastic.apm.agent.sdk.logging.LoggerFactory$1.run(LoggerFactory.java:65)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at co.elastic.apm.agent.sdk.logging.LoggerFactory.getLoggerFromFactory(LoggerFactory.java:65)
        at co.elastic.apm.agent.sdk.logging.LoggerFactory.getLogger(LoggerFactory.java:45)
        at co.elastic.apm.agent.sdk.logging.LoggerFactory.getLogger(LoggerFactory.java:56)
        at co.elastic.apm.agent.log4j2.reformatting.Log4J2EcsReformattingHelper.<clinit>(Log4J2EcsReformattingHelper.java:49)
        at co.elastic.apm.agent.log4j2.reformatting.Log4j2AppenderGetLayoutAdvice.<clinit>(Log4j2AppenderGetLayoutAdvice.java:37)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1155)
        at java.base/java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue(DirectMethodHandle.java:377)
        at java.base/java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue(DirectMethodHandle.java:374)
        at java.base/java.lang.ClassValue.getFromHashMap(ClassValue.java:228)
        at java.base/java.lang.ClassValue.getFromBackup(ClassValue.java:210)
        at java.base/java.lang.ClassValue.get(ClassValue.java:116)
        at java.base/java.lang.invoke.DirectMethodHandle.checkInitialized(DirectMethodHandle.java:400)
        at java.base/java.lang.invoke.DirectMethodHandle.ensureInitialized(DirectMethodHandle.java:388)
        at java.base/java.lang.invoke.DirectMethodHandle.internalMemberNameEnsureInit(DirectMethodHandle.java:338)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.appender.AbstractAppender.getLayout(AbstractAppender.java:264)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.start(AbstractOutputStreamAppender.java:163)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.config.AbstractConfiguration.setToDefault(AbstractConfiguration.java:731)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:47)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.LoggerContext.<init>(LoggerContext.java:84)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150)
        at org.apache.logging.log4j.core@2.17.2/org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
        at org.apache.logging.log4j@2.17.2/org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
        at org.apache.logging.log4j@2.17.2/org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
        at org.apache.logging.log4j@2.17.2/org.apache.logging.log4j.LogManager.getLogger(LogManager.java:585)
        at com.mycompany.servicebase.spring@50.1.0/com.mycompany.servicebase.spring.ToolboxService.<clinit>(ToolboxService.java:38)

```

**Steps to reproduce** :  
1.  
2.  
3.

**Errors in browser console (if relevant)**:

**Provide logs and/or server output (if relevant)**:

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [July 13, 2022, 8:38am UTC](https://discuss.elastic.co/t/jvm-crashes-with-apm-agent-1-33-and-jpms-enabled/309503/2 "2022-07-13T08:38:19Z")

</div>

Hey @emmettl , welcome to our forum and thanks for reporting!

Please share the entire stack trace. An NPE during instrumentation should not crash the app, so it would be interesting to see everything. From the part you shared, it looked as if it's on its way to stack overflow. Our safeguards of not instrumenting our own logging may be escaped in this case.  
If the error/log is too big, you can share through [https://gist.github.com/](https://gist.github.com/)

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [July 13, 2022, 8:45am UTC](https://discuss.elastic.co/t/jvm-crashes-with-apm-agent-1-33-and-jpms-enabled/309503/3 "2022-07-13T08:45:33Z")

</div>

Ahh, it may escape our checks because they rely on whether the class loader loading the logger is [an agent CL or not](https://github.com/elastic/apm-agent-java/blob/c8e7936b1a6a897aef609b820d20e254cd1440cc/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/reformatting/Log4j2EcsReformattingInstrumentation.java#L52). Maybe it is not identified in this case because JPMS does something differently...  
The full log may assist with analysis

---

<div class="post-metadata">

**Author:** ![emmettl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emmettl/32/108237_2.png) [@emmettl](https://discuss.elastic.co/u/emmettl)\
**Post date:** [July 13, 2022, 9:09am UTC](https://discuss.elastic.co/t/jvm-crashes-with-apm-agent-1-33-and-jpms-enabled/309503/4 "2022-07-13T09:09:47Z")

</div>

I've updated the full stack trace. Hope that helps.

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [July 13, 2022, 2:22pm UTC](https://discuss.elastic.co/t/jvm-crashes-with-apm-agent-1-33-and-jpms-enabled/309503/5 "2022-07-13T14:22:58Z")

</div>

Hi @emmettl thanks for this report. The agent currently fails when the application uses JPMS and they both (agent and application) have a common dependency. [The issue](https://github.com/elastic/apm-agent-java/issues/2373) has been identified but not yet prioritized.

---

<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:** [August 3, 2022, 10:23am UTC](https://discuss.elastic.co/t/jvm-crashes-with-apm-agent-1-33-and-jpms-enabled/309503/6 "2022-08-03T10:23:28Z")

</div>

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