[main] Warn when @PluginBuilderAttribute field lacks public setter (#3195 port)#4156
[main] Warn when @PluginBuilderAttribute field lacks public setter (#3195 port)#4156vpelikh wants to merge 3 commits into
@PluginBuilderAttribute field lacks public setter (#3195 port)#4156Conversation
The annotation processor now validates that every @PluginBuilderAttributevfield in a plugin builder class has an accessible public setter method (setXxx or withXxx). If no setter is found, a compilation ERROR is emitted. Use @SuppressWarnings("log4j.public.setter") on the field to suppress. Added @SuppressWarnings to known false positives in: - SocketPerformancePreferences (3 fields: setters return void, not builder) - StringMatchFilter (field 'text' has setter named 'setMatchString') - Rfc5424Layout (field 'enterpriseNumber' has no setter at all) Signed-off-by: Vasily Pelikh <2010720+vpelikh@users.noreply.github.com>
@PluginBuilderAttribute field lacks public setter (#3195 port)@PluginBuilderAttribute field lacks public setter (#3195 port)
|
However, your new processor works so well that it actually caught a pre-existing violation in main! When building locally, the compile fails in log4j-jdbc because JdbcAppender is missing public setters: Could you please update |
|
@vpelikh, Also, I noticed Spotless formatting on 3 PR as well. When you push your updates, please make sure to run |
The annotation processor requires @PluginBuilderAttribute setters to return a type assignable to the enclosing builder class. Changed setImmediateFail() and setReconnectIntervalMillis() from void to B, following the same pattern as all other setters in the Builder class. Fixes compilation errors caught by the new annotation processor validation: - The field immediateFail does not have a public setter. - The field reconnectIntervalMillis does not have a public setter. Signed-off-by: Vasily Pelikh <2010720+vpelikh@users.noreply.github.com>
Fixes formatting violations caught by spotless:check: - PluginProcessor: line wrapping, duplicate import removal - PluginProcessorPublicSetterTest: line wrapping consistency Signed-off-by: Vasily Pelikh <2010720+vpelikh@users.noreply.github.com>
552a04f to
a38185a
Compare
|
Thank you for the review, @ramanathan1504 ! Great catch – you're absolutely right, the new validation uncovered real issues in I've just pushed two commits that:
The build should be green now. Please take another look when you have a moment – happy to adjust anything else if needed. |
This ports the annotation processor validation from #3195 (2.x) to
main(3.x).What it does
The
PluginProcessorannotation processor now validates that every@PluginBuilderAttributefield in a plugin builder class has a publicsetXxx()orwithXxx()method that:publicIf no such setter is found, a compilation ERROR is emitted:
Suppressing false positives
Use
@SuppressWarnings("log4j.public.setter")on the field to suppress the warning for legitimate cases (e.g., fields set via constructor or reflection).Files changed
PluginProcessor.java— Added setter validation logic inprocessBuilderAttributeFields()PluginProcessorPublicSetterTest.java— Test with 3 cases: public setter OK, missing setter → error, suppressed → no errorFakePluginPublicSetter.java.source— Test plugin for the above testSocketPerformancePreferences.java— Added@SuppressWarningsto 3 fields (setters returnvoid, not builder type)StringMatchFilter.java— Added@SuppressWarnings(setMatchStringname doesn't match fieldtext)Rfc5424Layout.java— Added@SuppressWarnings(fieldenterpriseNumberhas no setter)Note
Unlike the 2.x version, the 3.x
PluginProcessoruses@SupportedAnnotationTypes({"org.apache.logging.log4j.plugins.Plugin", "org.apache.logging.log4j.plugins.PluginBuilderAttribute", "org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute"})and iterates by FQN, because 3.x has two@PluginBuilderAttributevariants.