Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
1.1.7
-
Windows
Linux
Java 1.7+
Description
When nested exceptions are used and the exception does not have a message, logback library prints null. However, the expected detail should be calling toString() instead of printing null. Difference is evident between logback library and java logging library.
class TestException extends Exception { private String exceptionCode; private String exceptionMessage; @Override public String toString() { return "TestException [exceptionCode=" + exceptionCode + ", exceptionMessage=" + exceptionMessage + "]"; } } try { TestException testException = new TestException(); testException.exceptionCode = "Test exception code"; testException.exceptionMessage = "Test exception message"; throw new IOException("Io message", testException); } catch (Exception e) { logger.error("Error message ", e); java.util.logging.Logger.getAnonymousLogger().log(java.util.logging.Level.SEVERE, "Error message", e); }
Prints the nested exceptions as:
// SLF4J logging java.io.IOException: Io message at test.Test.testMethod(Test.java:224) at test.Test.main(Test.java:119) Caused by: test.Test$1TestException: null at test.Test.testMethod(Test.java:221) ... 1 common frames omitted Nov 17, 2016 11:52:04 AM test.Test testMethod // Java Util logging SEVERE: Error message java.io.IOException: Io message at test.Test.testMethod(Test.java:224) at test.Test.main(Test.java:119) Caused by: TestException [exceptionCode=Test exception code, exceptionMessage=Test exception message] at test.Test.testMethod(Test.java:221) ... 1 more