Skip to content

Commit

Permalink
Fix format error when last argument is Throwable
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicwu committed Jul 15, 2022
1 parent 04b9c4b commit 9326785
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public static LogMessage of(Object format, Object... arguments) {
Object lastArg = arguments[len - 1];
if (lastArg instanceof Throwable) {
t = (Throwable) lastArg;
if (--len > 0) {
Object[] args = new Object[len];
System.arraycopy(arguments, 0, args, 0, len);
arguments = args;
}
}

if (len > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,13 @@ public void testMessageWithThrowable() {
msg = LogMessage.of("test %s", 1, t);
Assert.assertEquals("test 1", msg.getMessage());
Assert.assertEquals(t, msg.getThrowable());

msg = LogMessage.of("test %d %s", 1, t);
Assert.assertEquals("test 1 java.lang.Exception", msg.getMessage());
Assert.assertEquals(t, msg.getThrowable());

msg = LogMessage.of("test %d %s", 1, t, null);
Assert.assertEquals("test 1 java.lang.Exception", msg.getMessage());
Assert.assertEquals(msg.getThrowable(), null);
}
}

0 comments on commit 9326785

Please sign in to comment.