Skip to content
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

Open
wants to merge 8 commits into
base: 2.x
Choose a base branch
from

Conversation

JWT007
Copy link
Contributor

@JWT007 JWT007 commented Feb 27, 2025

#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
Copy link

github-actions bot commented Feb 27, 2025

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

Copy link
Contributor

@ppkarwasz ppkarwasz left a comment

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)
Copy link
Contributor

@ppkarwasz ppkarwasz left a 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:

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

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);
Copy link
Contributor

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
Contributor

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
Copy link
Contributor

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
Contributor

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
Contributor

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
Contributor

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
Contributor

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

@@ -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)) {
Copy link
Contributor

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
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants