[ 
https://issues.apache.org/jira/browse/LOG4J2-3609?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17611992#comment-17611992
 ] 

Matt Sicker commented on LOG4J2-3609:
-------------------------------------

I'm able to reproduce this issue in a unit test based on your test case. Upon 
further inspection, it seems to only happen when {{@MyAnnotation}} has a 
retention policy of {{CLASS}} (the default if unspecified) or {{{}RUNTIME{}}}; 
it works fine when the retention policy is {{{}SOURCE{}}}. This is a bit tricky 
to debug as annotation processing is already a tricky feature to debug in the 
first place. Let me see what I can figure out with further probing.

> javac error when PluginProcessor (log4j-core jar) is in the classpath and 
> annotation is not
> -------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-3609
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3609
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.19.0
>         Environment: The problem seems to be reproducible in every JDK. I 
> tested with JDK 8, 11, 19, and 19.
>            Reporter: Stamatis Zampetakis
>            Assignee: Matt Sicker
>            Priority: Major
>         Attachments: LOG4J2-3609-repro.tar.gz
>
>
> Java compilation (javac) fails to compile a class when the following 
> conditions hold:
> * the class transitively depends on an annotation;
> * the annotation is not in the classpath;
> * the log4j annotation processor (PluginProcessor) is in the classpath.
> Assuming that {{MyAnnotation.class}} is not in the classpath the error is the 
> one shown below.
> {noformat}
> error: cannot access MyAnnotation
>   class file for MyAnnotation not found
> 1 error
> {noformat}
> I admit that not including the annotation in the classpath could be 
> considered a problem in general but there is no reason why the compilation 
> should fail only when the log4j jar is in the classpath.
> It is pretty clear that the problem is related to the annotation processor 
> present in log4j-core jar (PluginProcessor) cause removing the respective 
> entries from the jar allows compilation to complete sucessfully.
> From the JDK perspective, it seems that this scenario was considered as a bug 
> and was fixed somewhere in JDK6 allowing compilation to proceed even when 
> annotations are missing from the classpath:
> https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6365854
> I will upload a minimal scenario with exact steps to reproduce the problem in 
> a few minutes.



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

Reply via email to