-
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
Hardens PropertiesUtil
against recursive property sources
#3263
base: 2.24.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,34 +24,36 @@ | |
import org.apache.logging.log4j.message.MessageFactory; | ||
import org.apache.logging.log4j.message.ParameterizedMessageFactory; | ||
import org.junit.jupiter.api.Test; | ||
import org.junitpioneer.jupiter.ClearSystemProperty; | ||
import org.junitpioneer.jupiter.SetSystemProperty; | ||
|
||
@SetSystemProperty( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By making this test-scoped, aren't you changing the
In the new case, you cannot know which configuration source has kicked in. |
||
key = "log4j2.messageFactory", | ||
value = "org.apache.logging.log4j.core.LoggerMessageFactoryCustomizationTest$TestMessageFactory") | ||
@SetSystemProperty( | ||
key = "log4j2.flowMessageFactory", | ||
value = "org.apache.logging.log4j.core.LoggerMessageFactoryCustomizationTest$TestFlowMessageFactory") | ||
class LoggerMessageFactoryCustomizationTest { | ||
|
||
@Test | ||
@ClearSystemProperty(key = "log4j2.messageFactory") | ||
@ClearSystemProperty(key = "log4j2.flowMessageFactory") | ||
void arguments_should_be_honored() { | ||
final LoggerContext loggerContext = | ||
new LoggerContext(LoggerMessageFactoryCustomizationTest.class.getSimpleName()); | ||
final Logger logger = new Logger( | ||
loggerContext, "arguments_should_be_honored", new TestMessageFactory(), new TestFlowMessageFactory()); | ||
assertTestMessageFactories(logger); | ||
try (LoggerContext loggerContext = | ||
new LoggerContext(LoggerMessageFactoryCustomizationTest.class.getSimpleName())) { | ||
Logger logger = new Logger( | ||
loggerContext, | ||
"arguments_should_be_honored", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
||
new TestMessageFactory(), | ||
new TestFlowMessageFactory()); | ||
assertTestMessageFactories(logger); | ||
} | ||
} | ||
|
||
@Test | ||
@SetSystemProperty( | ||
key = "log4j2.messageFactory", | ||
value = "org.apache.logging.log4j.core.LoggerMessageFactoryCustomizationTest$TestMessageFactory") | ||
@SetSystemProperty( | ||
key = "log4j2.flowMessageFactory", | ||
value = "org.apache.logging.log4j.core.LoggerMessageFactoryCustomizationTest$TestFlowMessageFactory") | ||
void properties_should_be_honored() { | ||
final LoggerContext loggerContext = | ||
new LoggerContext(LoggerMessageFactoryCustomizationTest.class.getSimpleName()); | ||
final Logger logger = new Logger(loggerContext, "properties_should_be_honored", null, null); | ||
assertTestMessageFactories(logger); | ||
try (LoggerContext loggerContext = | ||
new LoggerContext(LoggerMessageFactoryCustomizationTest.class.getSimpleName())) { | ||
Logger logger = loggerContext.getLogger("properties_should_be_honored"); | ||
assertTestMessageFactories(logger); | ||
} | ||
} | ||
|
||
private static void assertTestMessageFactories(Logger logger) { | ||
|
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.
Shall we also verify the status logger warning?