Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3609

javac error when PluginProcessor (log4j-core jar) is in the classpath and annotation is not

Agile BoardAttach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.19.0
    • None
    • Core
    • None
    • The problem seems to be reproducible in every JDK. I tested with JDK 8, 11, 19, and 19.

    Description

      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.

      error: cannot access MyAnnotation
        class file for MyAnnotation not found
      1 error
      

      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.

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            mattsicker Matt Sicker
            zabetak Stamatis Zampetakis

            Dates

              Created:
              Updated:

              Slack

                Issue deployment