-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #2380: Log messages with insufficient parameters should not throw exception. #2393
Fix issue #2380: Log messages with insufficient parameters should not throw exception. #2393
Conversation
…ld not throw exception.
log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see several tests being replaced by single-shot examples, please don't. Instead use a @ParameterizedTest
and provide several examples providing sufficient coverage. I also would like to see examples where arguments contain Throwable
s to match against the cases @ppkarwasz stated.
log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
Outdated
Show resolved
Hide resolved
log4j-api-test/src/test/java/org/apache/logging/log4j/message/ParameterFormatterTest.java
Outdated
Show resolved
Hide resolved
…throw exception.Add test cases.
…throw exception.Add test cases.
@vy @ppkarwasz Done, and added some test cases with the following scenarios:
But this case with no warn log:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!
It almost looks good to me, except we need to maintain Log4j semantics (which is the same as Logback < 1.1.0 semantics) for classifying a trailing Throwable
as part of the arguments or as "extra" argument.
log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
Outdated
Show resolved
Hide resolved
log4j-api-test/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java
Outdated
Show resolved
Hide resolved
…tion should not give waring log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the usage of args.length
, it looks good to me.
log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
Outdated
Show resolved
Hide resolved
Done. Because the argCount might be 0 in ReusableMessage, I made a non-zero judgment in advance. |
Thank you for your contribution. |
Fix issue #2380: Log messages with insufficient parameters should not throw exception.
In this PR, I modified the class
org.apache.logging.log4j.message.ParameterFormatter
.I deleted the codes about checking placeholderCount and argCount, if they weren't equal, it would throw an IllegalArgumentException.
At the same time, I also modified the corresponding test cases.
Close #2380
@ppkarwasz Please review the codes when you have time.