newrelic / newrelic-java-agent

The New Relic Java agent
Apache License 2.0
202 stars 143 forks source link

Add null checks to vertx 4.5.1 instrumentation #1927

Closed kanderson250 closed 4 months ago

kanderson250 commented 4 months ago

Resolves #1774

Customers were seeing NPEs after upgrading to version 8.9.0 of the agent, which added support for vertx 4.5.1. The NPEs were happening inside our AsyncHandlerWrapper class.

This PR updates the instrumentation to prevent the creation of an AsyncHandlerWrapper if the original resultHandler is null. A further null check is added to AsyncHandlerWrapper itself to safeguard against the possibility that handle might get called twice somewhere later in the code.

I added a unit test where the resultHandler is null. However, this test isn't a "true" test because the existing NPE doesn't cause the test to fail (this NPE occurs off the main thread). Instead, an ugly SEVERE message appears in the stack trace without the fix.

I wasn't able to find a way to improve the test to truly capture the NPE, but decided to leave it in just to verify that the transaction and future handling still works as expected.

codecov-commenter commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 70.67%. Comparing base (5dcd0a8) to head (fc2a52f). Report is 9 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1927 +/- ## ============================================ + Coverage 70.66% 70.67% +0.01% - Complexity 9858 9860 +2 ============================================ Files 826 826 Lines 39804 39792 -12 Branches 6062 6061 -1 ============================================ - Hits 28127 28123 -4 + Misses 8951 8946 -5 + Partials 2726 2723 -3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.