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

Fix(#2769): Modify the annotation processor in 2.x to give a warning if a plugin builder attribute does not have a public setter. #3195

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

Conversation

jaykataria1111
Copy link

The following commit modifies the annotation processor in 2.x to shell out a warning if the plugin builder attribute does not have a public setter.

A @SuppressWarnings("log4j.public.setter") attribute can be used to ignore this compilation warning incase it is a known issue.

Checklist

  • Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise
  • ./mvnw verify succeeds (if it fails due to code formatting issues reported by Spotless, simply run ./mvnw spotless:apply and retry)
  • Non-trivial changes contain an entry file in the src/changelog/.2.x.x directory
  • Tests for the changes are provided
  • Commits are signed (optional, but highly recommended)

@jaykataria1111 jaykataria1111 marked this pull request as ready for review November 9, 2024 11:15
@ppkarwasz ppkarwasz self-assigned this Nov 11, 2024
Copy link

github-actions bot commented Nov 11, 2024

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.

@jaykataria1111,

Thanks for your contribution! I added some minor remarks below.

If you haven't done it already, please sign the ASF ICLA.

@jaykataria1111
Copy link
Author

Sounds good @ppkarwasz let me fix and rebase this! 🙂

…rning if a plugin builder attribute does not have a public setter.
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.

LGTM, thanks!

}
}

private void processBuilderAttributes(final VariableElement element) {
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
private void processBuilderAttributes(final VariableElement element) {
private void processBuilderAttribute(final VariableElement element) {

Small typo.

@ppkarwasz ppkarwasz marked this pull request as ready for review November 23, 2024 11:01
@ppkarwasz
Copy link
Contributor

@jaykataria1111,

I sent you an invitation to the Apache Slack to the address you use in your commits.

@jaykataria1111
Copy link
Author

Hi @ppkarwasz the build was failing, hence I put the pr in draft 🥲. Thanks for approving it, but I will have to make a revision.

I am not sure I got the slack invitation, was the email [email protected]?

@ppkarwasz
Copy link
Contributor

No, I used the one from you University/Alma Mater that you use for your commits.

@jaykataria1111
Copy link
Author

Hi @ppkarwasz i am trying to move away from that email, because I don't have access to that anymore 🥲 will change it in my commits as well! I apologize

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.

Hi @jaykataria1111,

The OSGi fail is due to an "unauthorized" usage of Commons Lang 3. All optional Maven dependencies, must be explicitly marked as optional in OSGi, if we need them. In this case we don't.

import javax.tools.Diagnostic;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import org.apache.commons.lang3.StringUtils;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the reason the OSGi builds fail.

We don't have commons-lang3 as direct dependency. It is brought in the project by the optional commons-compress dependency.

BND does not automatically mark optional Maven dependencies as optional OSGi dependencies and for good reasons (see bndtools/bnd#2713 for a discussion), so the OSGi tests detected that the required org.apache.commons.lang3 package is missing. Please don't use Commons Lang 3, we are a bottom-of-the-stack library with no required dependencies.

* @param fieldName who's setter we are checking.
* @return The expected fieldName that will come after withxxxx or setxxxx
*/
public static String expectedFieldNameInASetter(String fieldName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make this private, we only expose public methods, when we need to.

Comment on lines +205 to +210
if (StringUtils.isEmpty(fieldName)) return ""; // Return empty string if the field is a blank String.

return String.format(
"%s%s",
fieldName.substring(0, 1).toUpperCase(Locale.ROOT),
fieldName.substring(1)); // we do not need to Lowercase here examples like field name 'ignoreExceptions'
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 (StringUtils.isEmpty(fieldName)) return ""; // Return empty string if the field is a blank String.
return String.format(
"%s%s",
fieldName.substring(0, 1).toUpperCase(Locale.ROOT),
fieldName.substring(1)); // we do not need to Lowercase here examples like field name 'ignoreExceptions'
return fieldName.isEmpty() ? fieldName : Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);

In this case, we don't need StringUtils.isEmpty(), since the argument is certainly non null. In the cases we need it, we have a copy in o.a.l.l.util.Strings.isEmpty().

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