How can an Exception be created/thrown with no stack trace?

OldCurmudgeon

I was trawling through some logs today and came across a strange error.

Here's how it appears in the log:

2014/09/11 15:23:52.801 [CC3A5FDD16035540B87F1B8C5E806588:<removed>] WARN a.b.c.Ddd - Main failure 
java.lang.NullPointerException: null
2014/09/11 15:23:52.801 [CC3A5FDD16035540B87F1B8C5E806588:<removed>] ...

and here's what the code looks like:

} catch (Exception e) {
    Ddd.log.warn("Main failure ", e);
    throw e;
}

The code is in a jsp if that is important. The same exception is repeated once more in the log (as you'd expect from the throw e).

I have no record of what the cause was - the previous line in the log shows execution of a query. This occurred just twice over a 4-day period and seems not to have caused any harm to the system.

Environment: Fairly busy web service running under Tomcat with Java 5.

I am not asking for tips on debugging the system - these errors are long-gone and may even never happen again. I was just stumped as to how any exception (especially an NPE) could be created without a stack trace?

Added

The logger being used is an slf4j driven Logback instance. I believe the warn method is here. Not sure what Logback method that resolves to but I am confident the Throwable parameter is treated specially and if there was an stack trace attached to the Throwable it would appear in the log.

LogBack.xml - as requested:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <property name="log.package" value="Package" />
  <property name="log.pattern" value="%date{yyyy/MM/dd HH:mm:ss.SSS} [%X{session}:%X{device}] %level %logger{25} - %msg%n"/> 
  <property name="log.consolePattern" value="%highlight(%-5level) %white(%logger{25}) - %msg%n"/> 
  <if condition='isDefined("catalina.home")'>
    <then>
      <property name="log.dir" value="${catalina.home}/logs" />
    </then>
    <else>
      <property name="log.dir" value="." />
    </else>
  </if>

  <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>DEBUG</level>
    </filter>
    <encoder>
      <Pattern>${log.consolePattern}</Pattern>
    </encoder>
  </appender>

  <appender name="rolling" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${log.dir}/${log.package}.log</file>
    <encoder>
      <Pattern>${log.pattern}</Pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>${log.dir}/${log.package}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
      <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
        <!-- or whenever the file size reaches 16MB. -->
        <maxFileSize>16MB</maxFileSize>
      </timeBasedFileNamingAndTriggeringPolicy>
      <!-- Keep no more than 3 months data. -->
      <maxHistory>90</maxHistory>
      <cleanHistoryOnStart>true</cleanHistoryOnStart>
    </rollingPolicy>
  </appender>

  <!-- Default logging levels. -->
  <root level="INFO">
    <appender-ref ref="console"/>
    <appender-ref ref="rolling"/>
  </root>
  <!-- Specific logging levels. -->
  <!-- Generally set to INFO or ERROR but if you need more details, set to DEBUG. -->
  <logger name="org.apache" level="INFO"/>
  <logger name="net.sf.ehcache" level="ERROR"/>
  <logger name="com.zaxxer" level="ERROR"/>
  <logger name="ch.qos" level="ERROR"/>
</configuration>

I hand-edited out the values after the session ID in the log to remove customer data.

emanciperingsivraren

Sometimes, especially when it comes to NullPointers (in my experience), the jvm can optimize the creation and casting of exceptions, and the stack trace is lost (or more correctly, never created). I suspect that your issue is not related to certain java libs, but rather the jvm itself.

If you add this argument when starting your jvm-process you will get your stack traces back, if my suspicion is correct.

-XX:-OmitStackTraceInFastThrow

This has been asked before, look here for more details:

Note, that this applies sun/oracle jvm

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to print the stack trace of an exception object in Python?

From Dev

How to use a stack trace dump to debug an exception?

From Dev

How to print the stack trace of an exception object in Python?

From Dev

How to use a stack trace dump to debug an exception?

From Dev

How does the console obtain the stack trace of an exception?

From Dev

How can I make program print a stack trace automatically when an Exception occurs in Android

From Java

How can I get a JavaScript stack trace when I throw an exception?

From Java

How can I convert a stack trace to a string?

From Dev

How to print the selenium exception stack trace in Extent reports

From Dev

How to get stack trace string without raising exception in python?

From Dev

Python exception: how to print the last ten lines of stack trace?

From Dev

How to get stack trace string without raising exception in python?

From Dev

how to read full exception stack trace from errorChannel

From Dev

How to print the selenium exception stack trace in Extent reports

From Dev

Exception Stack Trace Missing Items

From Dev

Why is the exception stack trace not logged in?

From Dev

how to trace this stack and pointer

From Java

How can I get the current stack trace in Java?

From Dev

How can I extract local variables from a stack trace?

From Dev

java - How can I get a future's stack trace on TimeoutException

From Dev

Exception that emails stack trace when raised

From Dev

locals() and globals() in stack trace on exception (Python)

From Dev

Rethrow an Exception with correct line numbers in the stack trace

From Dev

logback: newline before exception stack trace but not otherwise?

From Dev

Exception stack trace and aggregation in Parallel.ForEach

From Dev

Suppressing stack trace when catching exception

From Dev

locals() and globals() in stack trace on exception (Python)

From Dev

cxf null pointer exception without stack trace

From Dev

Printing the stack trace vs the exception itself

Related Related

  1. 1

    How to print the stack trace of an exception object in Python?

  2. 2

    How to use a stack trace dump to debug an exception?

  3. 3

    How to print the stack trace of an exception object in Python?

  4. 4

    How to use a stack trace dump to debug an exception?

  5. 5

    How does the console obtain the stack trace of an exception?

  6. 6

    How can I make program print a stack trace automatically when an Exception occurs in Android

  7. 7

    How can I get a JavaScript stack trace when I throw an exception?

  8. 8

    How can I convert a stack trace to a string?

  9. 9

    How to print the selenium exception stack trace in Extent reports

  10. 10

    How to get stack trace string without raising exception in python?

  11. 11

    Python exception: how to print the last ten lines of stack trace?

  12. 12

    How to get stack trace string without raising exception in python?

  13. 13

    how to read full exception stack trace from errorChannel

  14. 14

    How to print the selenium exception stack trace in Extent reports

  15. 15

    Exception Stack Trace Missing Items

  16. 16

    Why is the exception stack trace not logged in?

  17. 17

    how to trace this stack and pointer

  18. 18

    How can I get the current stack trace in Java?

  19. 19

    How can I extract local variables from a stack trace?

  20. 20

    java - How can I get a future's stack trace on TimeoutException

  21. 21

    Exception that emails stack trace when raised

  22. 22

    locals() and globals() in stack trace on exception (Python)

  23. 23

    Rethrow an Exception with correct line numbers in the stack trace

  24. 24

    logback: newline before exception stack trace but not otherwise?

  25. 25

    Exception stack trace and aggregation in Parallel.ForEach

  26. 26

    Suppressing stack trace when catching exception

  27. 27

    locals() and globals() in stack trace on exception (Python)

  28. 28

    cxf null pointer exception without stack trace

  29. 29

    Printing the stack trace vs the exception itself

HotTag

Archive