-
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
2791 Fix handling of onMatch
and onMismatch
attributes in the properties configuration format
#3505
base: 2.x
Are you sure you want to change the base?
2791 Fix handling of onMatch
and onMismatch
attributes in the properties configuration format
#3505
Conversation
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.
Thanks! 💯
I think we could profit from the occasion and add JSpecify annotation to all classes in this package. As far as I can tell only a few parameters and fields can be null
, mostly those named name
and value
.
...src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultComponentBuilder.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultComponentBuilder.java
Show resolved
Hide resolved
...src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultComponentBuilder.java
Outdated
Show resolved
Hide resolved
…Attributte (apache#2791) + more appropriate method name
+ made all Default***Builder implementations @ProviderrType + added setXXXAttribute method to some component builder interfaces with default implementations + added JSpecify @NullMarked to packages and @nullable where approrpiate to fields/mehods (per last PR review) + deprecated ComponentBuilder#addAttribute(...) methods and replaced with ComponentBuilder#setAttribute(...) methods in line with other builders (i.e. Plugins) - also since they don't just add but also remove if the value is null + reorganized ConfigurationBuilder to group getters, setters, builder factory methods + incremented package-info.java @Version annoations + added some null-guards in BuiltConfiguration#setup() + moved DeffaultConfigurationBuilder XML generation code from top to bottom of source file + removed "extra" attributes in Default***Builder constructors and replaced with setXXXAttribute chained calls in DefaultConfigurrationBuilder#newXXX(...) convenience methods + javadoc'd both packages (fixing documentation errors)
…instead of void (apache#2791) + added @BaselineIgnore due to API change (but breaks no code)
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.
Thanks for the PR! 💯
Overall it looks OK, I added some notes below:
try (final LoggerContext loggerContext1 = | ||
try (final LoggerContext tLoggerContext1 = |
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.
This isn't really necessary (and the 3 changes below).
*/ | ||
T addAttribute(String key, Level level); | ||
T setAttribute(String key, @Nullable Level level); |
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.
We can probably provide a default
implementation for these methods.
* @param level the level | ||
* @return this builder (for chaining) | ||
*/ | ||
default AppenderRefComponentBuilder setLevelAttribute(@Nullable String level) { |
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.
IMHO setLevel
would be a better naming choice: it is not ambiguous and it is shorter.
Should we remove the Attribute
suffix from all new methods?
|
||
/** | ||
* Container for building Configurations. This class is not normally directly manipulated by users | ||
* of the Assembler API. | ||
* @since 2.4 | ||
*/ | ||
@ProviderType |
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.
@ProviderType |
This class is not meant to be extended by neither consumers nor providers, so no annotation is needed.
* @param newValue the new value | ||
* @return the previous value or {@code null} if none was set | ||
*/ | ||
protected @Nullable String putAttribute(final String key, final @Nullable String newValue) { |
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.
Why is this protected
?
It has a better sounding name than addAttribute
. Maybe addAttribute
should be deprecated (possibly with an Error Prone @InlineMe
annotation) and this should be public
?
@Override | ||
public T addAttribute(final String key, final int value) { | ||
return put(key, Integer.toString(value)); | ||
public @NonNull CB getBuilder() { |
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.
public @NonNull CB getBuilder() { | |
public CB getBuilder() { |
Isn't @NonNull
the default?
synchronized (this) { | ||
attributes.clear(); | ||
components.clear(); | ||
} |
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.
Since the class is not thread-safe anyway, do we need this?
* Gets the list of child components. | ||
* @return an <i>immutable</i> list of the child components | ||
*/ | ||
protected List<Component> getComponents() { |
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.
protected List<Component> getComponents() { | |
protected List<? extends Component> getComponents() { |
@@ -334,7 +332,7 @@ private static <B extends ComponentBuilder<B>> ComponentBuilder<B> createCompone | |||
final ComponentBuilder<?> parent, final String key, final Properties properties) { | |||
final String name = (String) properties.remove(CONFIG_NAME); | |||
final String type = (String) properties.remove(CONFIG_TYPE); | |||
if (Strings.isEmpty(type)) { | |||
if (type == null || Strings.isEmpty(type)) { |
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.
if (type == null || Strings.isEmpty(type)) { | |
if (Strings.isEmpty(type)) { |
Strings.isEmpty
is null
-safe.
<issue id="2791" link="https://github.com/apache/logging-log4j2/issues/2791"/> | ||
<description format="asciidoc"> | ||
Fix problem when null attribute values are set on DefaultComponentBuilder. GitHub issue #2791. | ||
Added JVerify annotations to config.builder.* packages. |
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.
Added JVerify annotations to config.builder.* packages. | |
Added JSpecify annotations to config.builder.* packages. |
#2791
put(String, String)
to remove attributte if value is nullputAttribute(...)
implementations with object values against NPE(edit)
config.builder
andconfig.builder.api
packages