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

   Fixes #4441.
   
   `PluginBuilder` reads all declared fields of a builder class hierarchy. 
`GraalVmProcessor` registers only the builder fields that have one of its 
parameter annotations. On GraalVM CE 25.4.4.1.1, `getDeclaredFields()` also 
returns the fields that are not registered, and `Field.get()` on such a field 
throws `MissingReflectionRegistrationError`. Because of this, builders that 
have a static constant, a static logger, or another field without a plugin 
annotation fail. Examples are `LevelMatchFilter`, `SystemPropertyArbiter`, and 
the other builders in #4441.
   
   Also, `GraalVmProcessor` does not register builder fields that have 
`@PluginAttribute`, or that have only a constraint annotation such as 
`@Required`. `PluginBuilder` uses these fields. `Routes.Builder` and 
`KafkaAppender.Builder` use `@PluginAttribute` on fields.
   
   Changes:
   
   - `PluginBuilder` uses only the fields that have a plugin visitor or 
constraint annotation. It does not inject or validate other fields, so it does 
not read them.
   - `GraalVmProcessor` and `Annotations` handle `@PluginAttribute`, 
`@NotBlank`, `@Required`, `@ValidHost` and `@ValidPort`. Builder fields with 
these annotations are now registered. Method parameters do not change.
   
   Tests:
   
   - `PluginBuilderTest` checks which fields `PluginBuilder` uses.
   - `PluginBuilderTest` checks that the generated metadata of `log4j-core` 
registers each field that `PluginBuilder` uses, for all the builders in 
`log4j-core`.
   - `PluginBuilderTest` uses a builder that extends `AtomicInteger`. On Java 
16 and later, reflection on the private fields of `AtomicInteger` fails, in the 
same way as reflection on a field that is not registered in a native image. 
This checks that `build()` and `validateFields()` do not read the other fields.
   - The `GraalVmProcessorTest` fixture has a builder field with 
`@PluginAttribute` and a builder field with only `@Required`.
   - With the old `PluginBuilder` and the old processor lists, the new tests 
fail. With this change, they pass.
   - `mvn install` and `mvn site` pass on JDK 17 with Maven 3.9.16, with no 
test failures. I excluded only `AsyncLoggerUncachedThreadNameTest`. In my 
environment it also fails on `2.x` without this change, in 2 of 3 runs of the 
`test-disruptor-4` execution.
   - I ran the reproducer from #4441 as a native image on GraalVM CE 
25.4.4.1.1. With this change, the native output is the same as the JVM output.
   
   Limits:
   
   - `GraalVmProcessor` does not register fields that have only a custom 
visitor or constraint annotation from another project. This was also true 
before this change.
   - Plugins outside Log4j must be compiled again with the fixed 
`GraalVmProcessor` to get metadata for their `@PluginAttribute` fields. An 
example is `SpringBootTriggeringPolicyBuilder` in Spring Boot.
   
   ## Checklist
   
   * Base your changes on `2.x` branch if you are targeting Log4j 2; use `main` 
otherwise
   * `./mvnw verify` succeeds ([the build 
instructions](https://logging.apache.org/log4j/2.x/development.html#building))
   * Non-trivial changes contain an entry file in the `src/changelog/.2.x.x` 
directory
   * Tests are provided
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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