Jannik Zuther created LOG4J2-3652:
-------------------------------------

             Summary: jlink creates broken runtime image when using 
"--strip-debug" flag
                 Key: LOG4J2-3652
                 URL: https://issues.apache.org/jira/browse/LOG4J2-3652
             Project: Log4j 2
          Issue Type: Bug
          Components: API, Core, Plugins
    Affects Versions: 3.0.0
            Reporter: Jannik Zuther


I'm trying out the current `3.0.0-SNAPSHOT` (that's the ones from 2023-03-03) 
because I want to use Log4j 2 in a project with `jlink`. I've used `api`, 
`core`, and (transitively) `plugins`.
I'm using programmatic configuration (no configuration file), if that matters.

When using `jlink` with the `--strip-debug` flag with Log4j 2, the resulting 
runtime image seems to be broken. When trying to run it, Log4j 2 immediately 
spits out a giant number of errors and exceptions.
It looks like the Log4j 2 components essentially can't find their own 
attributes, nor the attributes of other components?
Here is some of the output (it's far too much to include it all):

```java
ERROR StatusConsoleListener Appender references must contain a reference: arg0
ERROR StatusConsoleListener Could not configure plugin element AppenderRef: 
org.apache.logging.log4j.plugins.validation.ConstraintValidationException: 
Validation failed for arg0 (source: java.lang.String arg0) and value null
 org.apache.logging.log4j.plugins.validation.ConstraintValidationException: 
Validation failed for arg0 (source: java.lang.String arg0) and value null
        at 
org.apache.logging.log4j.plugins@3.0.0-SNAPSHOT/org.apache.logging.log4j.plugins.di.DefaultInjector.validate(Unknown
 Source)
        at 
org.apache.logging.log4j.plugins@3.0.0-SNAPSHOT/org.apache.logging.log4j.plugins.di.DefaultInjector.lambda$getArguments$37(Unknown
 Source)
[...]
```

```java
ERROR StatusConsoleListener AppenderRef contains an invalid element or 
attribute "ref"
ERROR StatusConsoleListener Appender references must contain a reference: arg0
ERROR StatusConsoleListener Could not configure plugin element AppenderRef: 
org.apache.logging.log4j.plugins.validation.ConstraintValidationException: 
Validation failed for arg0 (source: java.lang.String arg0) and value null
[...]
```

```java
[...]
ERROR StatusConsoleListener Logger contains invalid attributes "name", "level"
ERROR StatusConsoleListener Logger has no field or parameter that matches 
element AppenderRef
ERROR StatusConsoleListener Logger has no field or parameter that matches 
element AppenderRef
ERROR StatusConsoleListener Skipping null child object with name Logger in 
element Loggers
ERROR StatusConsoleListener Loggers has no field or parameter that matches 
element Logger
ERROR StatusConsoleListener ThresholdFilter contains an invalid element or 
attribute "level"
ERROR StatusConsoleListener ThresholdFilter contains an invalid element or 
attribute "level"
[...]
```

When not using the `--strip-debug` flag, things seem to work fine.

Is this a known issue? Or even expected behavior? What is Log4j 2 doing that 
could be causing this? I can barely find any information about what exactly 
`--strip-debug` even strips from the runtime image.
Is this a problem related to reflection, possibly?

While the workaround is just not adding `--strip-debug`, this would likely trip 
up more people in the future. I spent almost two days until I found out that 
this was even the problem (which might just be my inexperience with the Java 
Platform Module System, though).

To reproduce this:

- Create a Java or Kotlin-JVM application that depends on Log4j 2 
`3.0.0-SNAPSHOT` and that has a `module-info.java`
- Do some Log4j things in the main method, like creating a logger and logging 
something - Create a runtime image from your application with `jlink`, 
including the `--strip-debug` flag
- Run that runtime image and observe the output



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to