java.lang.NullPointerException

QOS.ch JIRA | Cliff Zhao | 5 years ago
  1. 0

    In my tomcat environment, logback throws NullPointerException occasionally. The satack trace looks like: Exception in thread "Thread-5" java.lang.NullPointerException at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:135) at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:471) at ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:464) at ch.qos.logback.classic.Logger.debug(Logger.java:542) at com.alu.ipd.ode.customer.exponentiale.reporting.ram.RamMonitor$RamServerChecker.run(RamMonitor.java:140) Look at the code of LoggingEvent.java around line 135: LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC .getMDCAdapter(); mdcPropertyMap = logbackMDCAdapter.getPropertyMap(); Sometime the MDC.getMDCAdapter() returns null, which caused the NullPointerException. I did a lot of debugging, found that the exception would not happen if I watched the MDC.mdcAdapter with the debugger also found no changed to it. I believed that this must be a threading issue, and modified the MDC's static initializer as below: static final MDCAdapter mdcAdapter; static { MDCAdapter mdcAdapter1=null; try { mdcAdapter1 = StaticMDCBinder.SINGLETON.getMDCA(); } catch (NoClassDefFoundError ncde) { mdcAdapter1 = new NOPMDCAdapter(); String msg = ncde.getMessage(); if (msg != null && msg.indexOf("org/slf4j/impl/StaticMDCBinder") != -1) { Util.report("Failed to load class \"org.slf4j.impl.StaticMDCBinder\"."); Util.report("Defaulting to no-operation MDCAdapter implementation."); Util .report("See " + NO_STATIC_MDC_BINDER_URL + " for further details."); } else { throw ncde; } } catch (Exception e) { // we should never get here Util.report("MDC binding unsuccessful.", e); } finally { mdcAdapter = mdcAdapter1; } } NOTE: The key here is: make the mdcAdapter final. I used a temporary variable mdcAdapter1 and assigned it to mdcAdapter in the finally clause. After this change, the NullPointerException never happens. I used slf4j 1.6.2 and logback 0.9.29.

    QOS.ch JIRA | 5 years ago | Cliff Zhao
    java.lang.NullPointerException
  2. 0

    In my tomcat environment, logback throws NullPointerException occasionally. The satack trace looks like: Exception in thread "Thread-5" java.lang.NullPointerException at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:135) at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:471) at ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:464) at ch.qos.logback.classic.Logger.debug(Logger.java:542) at com.alu.ipd.ode.customer.exponentiale.reporting.ram.RamMonitor$RamServerChecker.run(RamMonitor.java:140) Look at the code of LoggingEvent.java around line 135: LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC .getMDCAdapter(); mdcPropertyMap = logbackMDCAdapter.getPropertyMap(); Sometime the MDC.getMDCAdapter() returns null, which caused the NullPointerException. I did a lot of debugging, found that the exception would not happen if I watched the MDC.mdcAdapter with the debugger also found no changed to it. I believed that this must be a threading issue, and modified the MDC's static initializer as below: static final MDCAdapter mdcAdapter; static { MDCAdapter mdcAdapter1=null; try { mdcAdapter1 = StaticMDCBinder.SINGLETON.getMDCA(); } catch (NoClassDefFoundError ncde) { mdcAdapter1 = new NOPMDCAdapter(); String msg = ncde.getMessage(); if (msg != null && msg.indexOf("org/slf4j/impl/StaticMDCBinder") != -1) { Util.report("Failed to load class \"org.slf4j.impl.StaticMDCBinder\"."); Util.report("Defaulting to no-operation MDCAdapter implementation."); Util .report("See " + NO_STATIC_MDC_BINDER_URL + " for further details."); } else { throw ncde; } } catch (Exception e) { // we should never get here Util.report("MDC binding unsuccessful.", e); } finally { mdcAdapter = mdcAdapter1; } } NOTE: The key here is: make the mdcAdapter final. I used a temporary variable mdcAdapter1 and assigned it to mdcAdapter in the finally clause. After this change, the NullPointerException never happens. I used slf4j 1.6.2 and logback 0.9.29.

    QOS.ch JIRA | 5 years ago | Cliff Zhao
    java.lang.NullPointerException
  3. 0

    Artifactory - Users - artifactory 2.0.0 and glassfish

    jfrog.org | 9 months ago
    java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Android: Saving Map State in Google map

    Stack Overflow | 11 months ago | Junie Negentien
    java.lang.RuntimeException: Unable to resume activity {com.ourThesis.junieNegentien2015/com.ourThesis.junieNegentien2015.MainActivity}: java.lang.NullPointerException

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at ch.qos.logback.classic.spi.LoggingEvent.<init>()
    2. Logback Classic Module
      Logger.debug
      1. ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:135)
      2. ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:471)
      3. ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:464)
      4. ch.qos.logback.classic.Logger.debug(Logger.java:542)
      4 frames
    3. com.alu.ipd
      RamMonitor$RamServerChecker.run
      1. com.alu.ipd.ode.customer.exponentiale.reporting.ram.RamMonitor$RamServerChecker.run(RamMonitor.java:140)
      1 frame