# No stacktrace in APM for nullpointerexception in Spring controller

**URL:** <https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187>\
**Category:** APM\
**Tags:** java\
**Created:** [October 3, 2024, 11:51am UTC](https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187 "2024-10-03T11:51:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Casper\_Thrane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casper_thrane/32/49777_2.png) [@Casper\_Thrane](https://discuss.elastic.co/u/Casper_Thrane)\
**Post date:** [October 3, 2024, 11:51am UTC](https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187/1 "2024-10-03T11:51:24Z")

</div>

Hi

We are experiencing getting no stacktrace on nullpointerexception in a Spring controller. We have no idea why? And no idea where to look?

Any help will be appreciated 🙂

/Casper

---

<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:** [October 3, 2024, 12:23pm UTC](https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187/2 "2024-10-03T12:23:27Z")

</div>

Hi !

Can you elaborate on your issue ?

- do you have a NPE exception thrown in your app and you want to have the agent to capture it
- does your app with the agent throws NPE when the agent is added
- does the agent reports an NPE in its logs but there is no visible effect on the application ?

---

<div class="post-metadata">

**Author:** ![Casper\_Thrane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casper_thrane/32/49777_2.png) [@Casper\_Thrane](https://discuss.elastic.co/u/Casper_Thrane)\
**Post date:** [October 3, 2024, 12:38pm UTC](https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187/3 "2024-10-03T12:38:52Z")

</div>

The transaction fails, and APM captures the exception. But it is only the first line, ending with "\n" of the stacktrace. So the stacktrace field is in the APM document.

---

<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:** [October 4, 2024, 9:05am UTC](https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187/4 "2024-10-04T09:05:20Z")

</div>

can you provide a copy of the document stored in ES and the original exception stack trace if you have it ?

Also, can you provide your agent version and configuration ?

---

<div class="post-metadata">

**Author:** ![Casper\_Thrane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casper_thrane/32/49777_2.png) [@Casper\_Thrane](https://discuss.elastic.co/u/Casper_Thrane)\
**Post date:** [October 7, 2024, 8:12am UTC](https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187/5 "2024-10-07T08:12:33Z")

</div>

This is our log line on local output. We are using ver. 1.51.

```auto
{"@timestamp":"2024-10-07T08:01:12.656Z","log.level":"ERROR","message":"null","ecs.version": "1.2.0","service.name":"tvangsoploesning-dirigent-service","event.dataset":"application","process.thread.name":"http-nio-9084-exec-2","log.logger":"dk.domstol.tvangsoploesning.dirigent.infrastructure.logging.TvangsoploesningExceptionControllerAdvice","transaction.id":"c94b4f21ac147405","event.action":"ERROR","trace.id":"6a7abb5a2d815fe61f97fc62126b3780","error.type":"java.lang.NullPointerException","error.id":"154e6df5474b741457282b7db337099b","error.type":"java.lang.NullPointerException","error.stack_trace":"java.lang.NullPointerException: null\n\tat java.util.Objects.requireNonNull(Objects.java:233)\n\tat d.d.t.d.domain.common.gateway.person.PersonIntern.<init>(PersonIntern.java:14)\n\tat d.d.t.d.d.common.gateway.person.PersonInternMapper.toInternal(PersonInternMapper.java:18)\n\tat java.util.Optional.map(Optional.java:260)\n\tat d.d.t.d.domain.common.gateway.person.PersonGateway.getById(PersonGateway.java:17)\n\tat d.d.t.d.domain.part.personreference.PersonService.getPartById(PersonService.java:29)\n\tat jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)\n\tat java.lang.reflect.Method.invoke(Method.java:580)\n\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355)\n\tat o.s.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)\n\tat o.s.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)\n\tat o.s.a.f.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat o.s.t.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:379)\n\tat o.s.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)\n\tat o.s.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)\n\tat o.s.a.f.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat o.s.a.f.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:720)\n\tat d.d.t.d.d.p.p.PersonService$$SpringCGLIB$$0.getPartById(<generated>)\n\tat d.d.t.dirigent.domain.part.PartService.getPersonPart(PartService.java:140)\n\tat d.d.t.dirigent.domain.part.PartService.getPart(PartService.java:118)\n\tat d.d.t.d.a.command.aktion.intern.OpretSagAktion.getTidligereLedelse(OpretSagAktion.java:195)\n\tat d.d.t.d.a.command.aktion.intern.OpretSagAktion.execute(OpretSagAktion.java:93)\n\tat d.d.t.d.a.c.aktion.intern.InternAktionService.opretSag(InternAktionService.java:105)\n\tat jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)\n\tat java.lang.reflect.Method.invoke(Method.java:580)\n\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355)\n\tat o.s.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)\n\tat o.s.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)\n\tat o.s.a.f.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat o.s.t.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:379)\n\tat o.s.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)\n\tat o.s.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)\n\tat o.s.a.f.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat o.s.a.f.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:720)\n\tat d.d.t.d.a.c.a.i.InternAktionService$$SpringCGLIB$$0.opretSag(<generated>)\n\tat d.d.t.dirigent.interfaces.rest.SagInternController.createSag(SagInternController.java:178)\n\tat jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)\n\tat java.lang.reflect.Method.invoke(Method.java:580)\n\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355)\n\tat o.s.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)\n\tat o.s.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)\n\tat o.s.a.f.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat o.s.s.a.m.AuthorizationManagerBeforeMethodInterceptor.proceed(AuthorizationManagerBeforeMethodInterceptor.java:269)\n\tat o.s.s.a.m.AuthorizationManagerBeforeMethodInterceptor.attemptAuthorization(AuthorizationManagerBeforeMethodInterceptor.java:264)\n\tat o.s.s.a.m.AuthorizationManagerBeforeMethodInterceptor.invoke(AuthorizationManagerBeforeMethodInterceptor.java:197)\n\tat o.s.s.c.a.m.c.DeferringMethodInterceptor.invoke(DeferringMethodInterceptor.java:44)\n\tat o.s.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)\n\tat o.s.a.f.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768)\n\tat o.s.a.f.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:720)\n\tat d.d.t.d.i.rest.SagInternController$$SpringCGLIB$$0.createSag(<generated>)\n\tat jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)\n\tat java.lang.reflect.Method.invoke(Method.java:580)\n\tat o.s.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:255)\n\tat o.s.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:188)\n\tat o.s.w.s.m.m.a.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118)\n\tat o.s.w.s.m.m.a.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:926)\n\tat o.s.w.s.m.m.a.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:831)\n\tat o.s.w.s.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089)\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979)\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914)\n\tat jakarta.servlet.http.HttpServlet.service(HttpServlet.java:547)\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)\n\tat jakarta.servlet.http.HttpServlet.service(HttpServlet.java:614)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\n\tat d.d.s.security.audit.log.audit.AuditLogUserFilter.doFilter(AuditLogUserFilter.java:32)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\n\tat c.a.o.validator.springmvc.OpenApiValidationFilter.doFilterInternal(OpenApiValidationFilter.java:61)\n\tat o.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\n\tat d.d.spring.logging.log.access.AccessLogApmFilter.doFilter(AccessLogApmFilter.java:27)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\n\tat d.d.spring.logging.log.audit.RequestMetadataFilter.doFilter(RequestMetadataFilter.java:26)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\n\tat o.s.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108)\n\tat org.springframework.security.web.FilterChainProxy.lambda$doFilterInternal$3(FilterChainProxy.java:231)\n\tat o.s.s.w.ObservationFilterChainDecorator$FilterObservation$SimpleFilterObservation.lambda$wrap$1(ObservationFilterChainDecorator.java:479)\n\tat o.s.s.w.ObservationFilterChainDecorator$AroundFilterObservation$SimpleAroundFilterObservation.lambda$wrap$1(ObservationFilterChainDecorator.java:340)\n\tat o.s.security.web.ObservationFilterChainDecorator.lambda$wrapSecured$0(ObservationFilterChainDecorator.java:82)\n\tat o.s.s.w.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:128)\n\tat o.s.s.web.access.intercept.AuthorizationFilter.doFilter(AuthorizationFilter.java:100)\n\tat o.s.s.w.ObservationFilterChainDecorator$ObservationFilter.wrapFilter(ObservationFilterChainDecorator.java:240)\n\tat o.s.s.w.ObservationFilterChainDecorator$ObservationFilter.doFilter(ObservationFilterChainDecorator.java:227)\n\tat o.s.s.w.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:137)\n\tat o.s.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:126)\n\tat o.s.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:120)\n\tat o.s.s.w.ObservationFilterChainDecorator$ObservationFilter.wrapFilter(ObservationFilterChainDecorator.java:240)\n\tat o.s.s.w.ObservationFilterChainDecorator$ObservationFilter.doFilter(ObservationFilterChainDecorator.java:227)\n\tat o.s.s.w.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:137)\n\tat o.s.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:131)\n\tat o.s.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:85)\n\t... 91 frames truncated\n"}

```

this is our APM config:

```auto
        - name: ELASTIC_APM_SERVER_URLS
          value: 'https://XXXXXXXXXXX:443'
        - name: ELASTIC_APM_SERVICE_NAME
          value: adgangsprofil-register-spring
        - name: ELASTIC_APM_APPLICATION_PACKAGES
          value: dk.domstol
        - name: ELASTIC_APM_ENVIRONMENT
          value: development
        - name: ELASTIC_APM_LOG_LEVEL
          value: INFO
        - name: JAVA_TOOL_OPTIONS
          value: '-javaagent:/elastic/apm/agent/elastic-apm-agent.jar'
        - name: ELASTIC_APM_VERIFY_SERVER_CERT
          value: 'false'

```

---

<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:** [October 7, 2024, 1:38pm UTC](https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187/6 "2024-10-07T13:38:00Z")

</div>

The stack trace is in the log line you provided (the NPE is from `d.d.t.d.domain.common.gateway.person.PersonIntern.<init>(PersonIntern.java:14)`)

---

<div class="post-metadata">

**Author:** ![Casper\_Thrane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casper_thrane/32/49777_2.png) [@Casper\_Thrane](https://discuss.elastic.co/u/Casper_Thrane)\
**Post date:** [October 7, 2024, 2:01pm UTC](https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187/7 "2024-10-07T14:01:11Z")

</div>

Yes, but APM doesn't capture the stacktrace. We want to know why.

---

<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:** [October 7, 2024, 2:57pm UTC](https://discuss.elastic.co/t/no-stacktrace-in-apm-for-nullpointerexception-in-spring-controller/368187/8 "2024-10-07T14:57:31Z")

</div>

That log line is showing the stack trace in the `error.stack_trace` field, where are you expecting to see it?
