Buggy code:
@ Provider public class InstrumentedMetricsEventListener implements ApplicationEventListener { private final MetricRegistry metrics ; private final AtomicReference < RequestEventListener > listener = new AtomicReference < > ( ) ; @ Inject public InstrumentedMetricsEventListener ( final MetricRegistry metrics ) { } @ SuppressWarnings ( "TypeMayBeWeakened" ) private static class GenericRequestEventListener implements RequestEventListener { private static final String METHOD_PREFIX = "httpMethods" ; private static final String STATUS_CODE_PREFIX = "responseCodes" ; private static final String STATUS_FAMILY_PREFIX = "responseFamilies" ; private final MetricRegistry registry ; private final Timer requestTimer ; private final Counter activeRequests ; private Context requestTimerContext ; private GenericRequestEventListener ( final MetricRegistry registry ) { } private static void markMethod ( final String method , final MetricRegistry registry ) { } private static void markStatus ( final StatusType status , final MetricRegistry registry ) { } private void registerMeters ( ) { } private void registerMethods ( ) { } private void registerStatuses ( ) { } @ Override public void onEvent ( final RequestEvent event ) { if ( ( event . getType ( ) ) == ( Type . MATCHING_START ) ) { activeRequests . inc ( ) ; requestTimerContext = requestTimer . time ( ) ; InstrumentedMetricsEventListener . GenericRequestEventListener . markMethod ( event . getContainerRequest ( ) . getMethod ( ) , registry ) ; } else if ( ( event . getType ( ) ) == ( Type . ON_EXCEPTION ) ) { @ SuppressWarnings ( "ThrowableResultOfMethodCallIgnored" ) final Throwable cause = event . getException ( ) . getCause ( ) ; if ( cause != null ) { registry . meter ( name ( "exceptions" , cause . getClass ( ) . getName ( ) ) ) . mark ( ) ; } } else if ( ( event . getType ( ) ) == ( Type . FINISHED ) ) { activeRequests . dec ( ) ; if ( ( requestTimerContext ) != null ) { requestTimerContext . close ( ) ; requestTimerContext = null ; } if ( ( event . getContainerResponse ( ) ) != null ) { InstrumentedMetricsEventListener . GenericRequestEventListener . markStatus ( event . getContainerResponse ( ) . getStatusInfo ( ) , registry ) ; } } } } private static class TimerRequestEventListener implements RequestEventListener { private final ImmutableMap < Method , Timer > timers ; private final Map < ContainerRequest , Context > contexts ; public TimerRequestEventListener ( final ImmutableMap < Method , Timer > timers ) { } @ Override public void onEvent ( final RequestEvent event ) { final ContainerRequest containerRequest = event . getContainerRequest ( ) ; if ( ( event . getType ( ) ) == ( Type . RESOURCE_METHOD_START ) ) { InstrumentedMetricsEventListener . getDefinitionMethod ( event ) . flatMap ( ( m ) -> Optional . ofNullable ( timers . get ( m ) ) ) . ifPresent ( ( timer ) -> { final Context context = timer . time ( ) ; contexts . put ( containerRequest , context ) ; } ) ; } else if ( ( event . getType ( ) ) == ( Type . RESOURCE_METHOD_FINISHED ) ) { Optional . ofNullable ( contexts . get ( containerRequest ) ) . ifPresent ( ( context ) -> { context . close ( ) ; contexts . remove ( containerRequest , context ) ; } ) ; } else if ( ( event . getType ( ) ) == ( Type . ON_EXCEPTION ) ) { Optional . ofNullable ( contexts . get ( containerRequest ) ) . ifPresent ( ( context ) -> { context . close ( ) ; contexts . remove ( containerRequest , context ) ; } ) ; } } } private static class MeterRequestEventListener implements RequestEventListener { private final ImmutableMap < Method , Meter > meters ; public MeterRequestEventListener ( final ImmutableMap < Method , Meter > meters ) { } @ Override public void onEvent ( final RequestEvent event ) { if ( ( event . getType ( ) ) == ( Type . RESOURCE_METHOD_START ) ) { <START_BUG> InstrumentedMetricsEventListener . getDefinitionMethod ( event ) . map ( meters :: get ) . ifPresent ( Meter :: mark ) ; <END_BUG> } } } private static Optional < Method > getDefinitionMethod ( final RequestEvent event ) { } private static class ChainedRequestEventListener implements RequestEventListener { private final RequestEventListener [ ] listeners ; private ChainedRequestEventListener ( final RequestEventListener ... listeners ) { } @ Override public void onEvent ( final RequestEvent event ) { for ( final RequestEventListener listener : listeners ) { listener . onEvent ( event ) ; } } } @ Override public void onEvent ( final ApplicationEvent event ) { } @ Override public RequestEventListener onRequest ( final RequestEvent event ) { } private void registerTimedAnnotations ( final ImmutableMap . Builder < Method , Timer > builder , final ResourceMethod method ) { } private void registerMeteredAnnotations ( final ImmutableMap . Builder < Method , Meter > builder , final ResourceMethod method ) { } private static < M extends Metric , A extends Annotation > void registerMetricsAnnotations ( final ImmutableMap . Builder < Method , M > builder , final ResourceMethod method , final Class < A > annotationClass , final Function < String , M > creator ) { } private static < A extends Annotation > boolean isAnnotatedWith ( final Class < A > annotationClass , final Method bottomDefinitionMethod ) { } private static String getMetricsName ( final ResourceMethod method ) { } private static void addHttpMethod ( final ResourceMethod method , final StringBuilder nameBuilder ) { } private static void addPathNames ( final ResourceMethod method , final StringBuilder nameBuilder ) { } private static void addProducedTypes ( final Producing method , final StringBuilder nameBuilder ) { } }

Fix:
InstrumentedMetricsEventListener . getDefinitionMethod ( event ) . flatMap ( ( m ) -> Optional . ofNullable ( meters . get ( m ) ) ) . ifPresent ( Meter :: mark ) ;