vpelikh opened a new pull request, #4156:
URL: https://github.com/apache/logging-log4j2/pull/4156

   This ports the annotation processor validation from #3195 (2.x) to `main` 
(3.x).
   
   ### What it does
   The `PluginProcessor` annotation processor now validates that every 
`@PluginBuilderAttribute` field in a plugin builder class has a public 
`setXxx()` or `withXxx()` method that:
   
   1. Takes exactly 1 parameter matching the field type
   2. Returns a type assignable to the enclosing builder class
   3. Is declared `public`
   
   If no such setter is found, a compilation **ERROR** is emitted:
   
   ```
   The field `myField` does not have a public setter. Note that
   @SuppressWarnings("log4j.public.setter") can be used on the field to
   suppress the compilation error.
   ```
   
   ### 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 in 
`processBuilderAttributeFields()`
   - **`PluginProcessorPublicSetterTest.java`** — Test with 3 cases: public 
setter OK, missing setter → error, suppressed → no error
   - **`FakePluginPublicSetter.java.source`** — Test plugin for the above test
   - **`SocketPerformancePreferences.java`** — Added `@SuppressWarnings` to 3 
fields (setters return `void`, not builder type)
   - **`StringMatchFilter.java`** — Added `@SuppressWarnings` (`setMatchString` 
name doesn't match field `text`)
   - **`Rfc5424Layout.java`** — Added `@SuppressWarnings` (field 
`enterpriseNumber` has no setter)
   
   ### Note
   Unlike the 2.x version, the 3.x `PluginProcessor` uses 
`@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 `@PluginBuilderAttribute` variants.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to