Skip to content

2791 Fix handling of onMatch and onMismatch attributes in the properties configuration format#3505

Closed
JWT007 wants to merge 8 commits into
apache:2.xfrom
JWT007:2791-fix-handling-of-onmatch-and-onmisma
Closed

2791 Fix handling of onMatch and onMismatch attributes in the properties configuration format#3505
JWT007 wants to merge 8 commits into
apache:2.xfrom
JWT007:2791-fix-handling-of-onmatch-and-onmisma

Conversation

@JWT007

@JWT007 JWT007 commented Feb 27, 2025

Copy link
Copy Markdown
Contributor

#2791

  • Updated DefaultComponentBuilder put(String, String) to remove attributte if value is null
  • Updated DefaultComponentBuilder guarded putAttribute(...) implementations with object values against NPE
  • updated javadoc
  • added changelog

(edit)

  • per @ppkarwasz review added JVerify annotations to config.builder and config.builder.api packages
  • optimized builder APIs and Default***ComponentBuilder implementations
  • changed (deprecated) 'addAttribute' methods to 'setAttribute' to better match other builder APIs
  • added convencience APIs for setting general attributes on ***ComponentBuilder interfaces
  • javadoc'd both packages 100%
  • updated callers of now deprecated APIs
  • updated changelog

@JWT007
JWT007 requested a review from ppkarwasz February 27, 2025 19:19
@github-actions

github-actions Bot commented Feb 27, 2025

Copy link
Copy Markdown
Contributor
Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 Build Scan PUBLISHED
Generated by gradle/develocity-actions

@ppkarwasz ppkarwasz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JWT007,

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.

+ 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)

@ppkarwasz ppkarwasz left a comment

Copy link
Copy Markdown
Member

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:

Comment on lines -85 to +84
try (final LoggerContext loggerContext1 =
try (final LoggerContext tLoggerContext1 =

Copy link
Copy Markdown
Member

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).

* @throws NullPointerException if the given {@code key} is {@code null}
*/
T addAttribute(String key, Level level);
T setAttribute(String key, @Nullable Level level);

Copy link
Copy Markdown
Member

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) {

Copy link
Copy Markdown
Member

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?

* of the Assembler API.
* @since 2.4
*/
@ProviderType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@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) {

Copy link
Copy Markdown
Member

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() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public @NonNull CB getBuilder() {
public CB getBuilder() {

Isn't @NonNull the default?

Comment on lines +163 to +166
synchronized (this) {
attributes.clear();
components.clear();
}

Copy link
Copy Markdown
Member

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() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected List<Component> getComponents() {
protected List<? extends Component> getComponents() {

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)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Added JVerify annotations to config.builder.* packages.
Added JSpecify annotations to config.builder.* packages.

@ppkarwasz ppkarwasz added this to the 2.25.0 milestone Apr 13, 2025
@ppkarwasz ppkarwasz modified the milestones: 2.25.0, 2.25.1 May 25, 2025
@ppkarwasz ppkarwasz removed this from the 2.25.1 milestone Jun 21, 2025
@vy

vy commented Apr 28, 2026

Copy link
Copy Markdown
Member

@ramanathan1504, is this something you might want to pick up?

@ramanathan1504

Copy link
Copy Markdown
Contributor

@vy, Yes, I can pick this up. I will review this PR and the issue discussion and come up with updated one.

@vy

vy commented May 28, 2026

Copy link
Copy Markdown
Member

Superseded by #4116.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants