Buggy code:
public class ElasticsearchReporter extends ScheduledReporter { public static ElasticsearchReporter . Builder forRegistry ( MetricRegistry registry ) { } public static class Builder { private final MetricRegistry registry ; private Clock clock ; private String prefix ; private TimeUnit rateUnit ; private TimeUnit durationUnit ; private MetricFilter filter ; private String [ ] hosts = new String [ ] { "localhost:9200" } ; private String index = "metrics" ; private String indexDateFormat = "yyyy-MM" ; private int bulkSize = 2500 ; private Notifier percolationNotifier ; private MetricFilter percolationFilter ; private int timeout = 1000 ; private String timestampFieldname = "@timestamp" ; private Map < String , Object > additionalFields ; private boolean saveEntryOnInstantiation = false ; private Builder ( MetricRegistry registry ) { } public ElasticsearchReporter . Builder withClock ( Clock clock ) { } public ElasticsearchReporter . Builder prefixedWith ( String prefix ) { } public ElasticsearchReporter . Builder convertRatesTo ( TimeUnit rateUnit ) { } public ElasticsearchReporter . Builder convertDurationsTo ( TimeUnit durationUnit ) { } public ElasticsearchReporter . Builder filter ( MetricFilter filter ) { } public ElasticsearchReporter . Builder hosts ( String ... hosts ) { } public ElasticsearchReporter . Builder timeout ( int timeout ) { } public ElasticsearchReporter . Builder index ( String index ) { } public ElasticsearchReporter . Builder indexDateFormat ( String indexDateFormat ) { } public ElasticsearchReporter . Builder bulkSize ( int bulkSize ) { } public ElasticsearchReporter . Builder percolationFilter ( MetricFilter percolationFilter ) { } public ElasticsearchReporter . Builder percolationNotifier ( Notifier notifier ) { } public ElasticsearchReporter . Builder timestampFieldname ( String fieldName ) { } public ElasticsearchReporter . Builder additionalFields ( Map < String , Object > additionalFields ) { } public ElasticsearchReporter . Builder saveEntryOnInstantiation ( boolean saveEntryOnInstantiation ) { } public ElasticsearchReporter build ( ) throws IOException { } } private static final Logger LOGGER = LoggerFactory . getLogger ( ElasticsearchReporter . class ) ; private final String [ ] hosts ; private final Clock clock ; private final String prefix ; private final String index ; private final int bulkSize ; private final int timeout ; private final ObjectMapper objectMapper = new ObjectMapper ( ) ; private final ObjectWriter writer ; private MetricFilter percolationFilter ; private Notifier notifier ; private String currentIndexName ; private SimpleDateFormat indexDateFormat = null ; private boolean checkedForIndexTemplate = false ; private boolean saveEntryOnInstantiation ; public ElasticsearchReporter ( MetricRegistry registry , String [ ] hosts , int timeout , String index , String indexDateFormat , int bulkSize , Clock clock , String prefix , TimeUnit rateUnit , TimeUnit durationUnit , MetricFilter filter , MetricFilter percolationFilter , Notifier percolationNotifier , String timestampFieldname , boolean saveEntryOnInstantiation , Map < String , Object > additionalFields ) throws MalformedURLException { } @ Override public void start ( long period , TimeUnit unit ) { super . start ( period , unit ) ; if ( saveEntryOnInstantiation ) { new ElasticsearchReporter . HttpConnectionTemplate ( ) { @ Override protected HttpURLConnection performAction ( HttpURLConnection connection , long timestamp ) throws IOException { <START_BUG> JsonMetric jsonMetric = new JsonStartTime ( name ( prefix , "metricStart" ) ) ; <END_BUG> connection = writeJsonMetricAndRecreateConnectionIfNeeded ( jsonMetric , connection , new AtomicInteger ( 0 ) ) ; return connection ; } } . write ( ) ; } } @ Override public void report ( final SortedMap < String , Gauge > gauges , final SortedMap < String , Counter > counters , final SortedMap < String , Histogram > histograms , final SortedMap < String , Meter > meters , final SortedMap < String , Timer > timers ) { } private abstract class HttpConnectionTemplate { public void write ( ) { } protected abstract HttpURLConnection performAction ( HttpURLConnection connection , long timestamp ) throws IOException { } } private List < String > getPercolationMatches ( JsonMetric jsonMetric ) throws IOException { } private void addJsonMetricToPercolationIfMatching ( JsonMetric < ? extends Metric > jsonMetric , List < JsonMetric > percolationMetrics ) { } private HttpURLConnection writeJsonMetricAndRecreateConnectionIfNeeded ( JsonMetric jsonMetric , HttpURLConnection connection , AtomicInteger entriesWritten ) throws IOException { } private void closeConnection ( HttpURLConnection connection ) throws IOException { } private HttpURLConnection createNewConnectionIfBulkSizeReached ( HttpURLConnection connection , int entriesWritten ) throws IOException { } private void writeJsonMetric ( JsonMetric jsonMetric , ObjectWriter writer , OutputStream out ) throws IOException { } private HttpURLConnection openConnection ( String uri , String method ) { } private void checkForIndexTemplate ( ) { } }

Fix:
JsonMetric jsonMetric = new JsonStartTime ( name ( prefix , "metricStart" ) , timestamp ) ;