Skip to content

NPE on smallrye-metrics JsonExporter on Java 8 when empty/null tags #434

@davsclaus

Description

@davsclaus

Notice this test error on Apache Camel where we are using smallrye metrics 3.0.3

https://ci-builds.apache.org/job/Camel/job/Apache%20Camel/job/main/121/testReport/junit/org.apache.camel.component.microprofile.metrics.message.history/MicroProfileMetricsExceptionInRouteMessageHistoryTest/testMetricsHistoryWhenRouteThrowsException/

java.lang.NullPointerException
	at java.util.TreeMap.putAll(TreeMap.java:313)
	at io.smallrye.metrics.exporters.JsonExporter.createTagsString(JsonExporter.java:350)
	at io.smallrye.metrics.exporters.JsonExporter.lambda$exportMetricsByName$5(JsonExporter.java:175)
	at java.util.HashMap.forEach(HashMap.java:1289)
	at io.smallrye.metrics.exporters.JsonExporter.exportMetricsByName(JsonExporter.java:173)
	at io.smallrye.metrics.exporters.JsonExporter.lambda$exportMetricsForMap$9(JsonExporter.java:214)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.HashMap$EntrySpliterator.forEachRemaining(HashMap.java:1699)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485)
	at io.smallrye.metrics.exporters.JsonExporter.exportMetricsForMap(JsonExporter.java:215)
	at io.smallrye.metrics.exporters.JsonExporter.exportOneRegistry(JsonExporter.java:199)
	at io.smallrye.metrics.exporters.JsonExporter.exportOneScope(JsonExporter.java:71)
	at org.apache.camel.component.microprofile.metrics.message.history.MicroProfileMetricsExceptionInRouteMessageHistoryTest.testMetricsHistoryWhenRouteThrowsException(MicroProfileMetricsExceptionInRouteMessageHistoryTest.java:60)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)

This only happens on Java 8, the same test works on Java 11.

The unit test is here
https://github.com/apache/camel/blob/main/components/camel-microprofile/camel-microprofile-metrics/src/test/java/org/apache/camel/component/microprofile/metrics/message/history/MicroProfileMetricsExceptionInRouteMessageHistoryTest.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions