Skip to content

NPE if JUL Handler does not have a Formatter #1302

@rroesch1

Description

@rroesch1
  • JUL Handlers can have a Formatter, but that's optional (i.e. java.util.logging.Handler#getFormatter may return null)
  • Cleaned up logging #1219 introduced code which tries to access the formatter without proper null-check
  • the JVM crashes with a NPE if a JUL Handler without formatter is in use (e.g. SLF4JBridgeHandler)
Exception in thread "main" java.lang.ExceptionInInitializerError
	at io.prometheus.jmx.JavaAgent.<clinit>(JavaAgent.java:39)
	at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
	at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unknown Source)
	at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.ensureClassInitialized(Unknown Source)
	at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.newMethodAccessor(Unknown Source)
	at java.base/jdk.internal.reflect.ReflectionFactory.newMethodAccessor(Unknown Source)
	at java.base/java.lang.reflect.Method.acquireMethodAccessor(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source)
Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because the return value of "java.util.logging.Handler.getFormatter()" is null
	at e1723a08afd7bca35570fd31a7656f59.io.prometheus.jmx.logger.LoggerFactory.<clinit>(LoggerFactory.java:37)
	... 10 more
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message Outstanding error when calling method in invokeJavaAgentMainMethod at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 627
*** java.lang.instrument ASSERTION FAILED ***: "success" with message invokeJavaAgentMainMethod failed at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 466
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 429
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x9b7d69]  jni_FatalError+0x79
V  [libjvm.so+0xb20644]  JvmtiExport::post_vm_initialized()+0x394
V  [libjvm.so+0xf906b1]  Threads::create_vm(JavaVMInitArgs*, bool*)+0x8a1
V  [libjvm.so+0x9b84af]  JNI_CreateJavaVM+0x4f
C  [libjli.so+0x970b]  JavaMain+0x8b
C  [libjli.so+0xd259]  ThreadJavaMain+0x9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions