Spring Framework
  1. Spring Framework
  2. SPR-9233

Reduce log level for message re: missing annotation

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 3.1.1
    • Fix Version/s: 3.2 M1
    • Component/s: Core
    • Labels:
    • Last commented by a User:
      false

      Description

      Since 3.1.1 the AbstractRecursiveAnnotationVisitor logs a warning when annotation class could not be loaded (see AbstractRecursiveAnnotationVisitor#logNonFatalException). Until 3.1.0 any Exception was catched without any message. I agree to log this but IMO this should be a debug log message. Annotations (even if RetentionPolicy.RUNTIME) may or may not be available at run-time. See also Java Language Specification:

      9.6.1.2 Retention

      Annotations may be present only in the source code, or they may be present in the binary form of a class or interface. An annotation that is present in the binary may or may not be available at run-time via the reflective libraries of the Java platform.
      ...

      So there is nothing wrong about getting a ClassNotFoundException regarding annotations.

      I suggest to change the log level to debug or (IMO better) to catch ClassNotFoundException -> logger.debug(...) because it's legitimate and any other Exception -> logger.warn(...).

      Background: We currently use jsr305 with @javax.annotation.Nonnull and @javax.annotation.Nullable doing some code analyses during builds. At run-time these annotations are no longer available/needed and we get tons of warnings "Failed to classload type while reading annotation metadata. This is a non-fatal error, but certain annotation metadata may be unavailable.". Of course, it's not a problem to workaround this: we can include jsr305 or change log level in config of this logger but IMO I should not get a warning when everything is like expected and JLS-compliant.

        Issue Links

          Activity

          Hide
          Chris Beams added a comment -

          Good point, thanks. We're working on other logging-related efforts for 3.2 M1 as it is, so this will fit in nicely.

          Show
          Chris Beams added a comment - Good point, thanks. We're working on other logging-related efforts for 3.2 M1 as it is, so this will fit in nicely.
          Hide
          Bernd Götz added a comment -

          I could live with a warning but what's really cluttering the startup of the application is the output of the stack trace for it.

          Show
          Bernd Götz added a comment - I could live with a warning but what's really cluttering the startup of the application is the output of the stack trace for it.
          Hide
          Chris Beams added a comment -
          commit 535d31f8d43029ff4a53238c787a52d770f8532c
          Author: Chris Beams <cbeams@vmware.com>
          Date:   Sun May 27 13:27:39 2012 +0300
          
              Reduce log level for message re: missing annotation
              
              Previously (since Spring 3.1.1) RecursiveAnnotationAttributesVisitor
              logs at level WARN when ASM parsing encounters an annotation or an (enum
              used within an annotation) that cannot be classloaded. This is not
              necessarily indicative of an error, e.g. JSR-305 annotations such as
              @Nonnull may be used only for static analysis purposes, but because
              these annotations have runtime retention, they remain present in the
              bytecode. Per section 9.6.1.2 of the JLS, "An annotation that is present
              in the binary may or may not be available at run-time via the reflective
              libraries of the Java platform."
              
              This commit lowers the log level of these messages from warn to debug,
              but leaves at warn level other messages dealing with the ability
              reflectively read enum values from within annotations.
              
              Issue: SPR-9233
          
          Show
          Chris Beams added a comment - commit 535d31f8d43029ff4a53238c787a52d770f8532c Author: Chris Beams <cbeams@vmware.com> Date: Sun May 27 13:27:39 2012 +0300 Reduce log level for message re: missing annotation Previously (since Spring 3.1.1) RecursiveAnnotationAttributesVisitor logs at level WARN when ASM parsing encounters an annotation or an (enum used within an annotation) that cannot be classloaded. This is not necessarily indicative of an error, e.g. JSR-305 annotations such as @Nonnull may be used only for static analysis purposes, but because these annotations have runtime retention, they remain present in the bytecode. Per section 9.6.1.2 of the JLS, "An annotation that is present in the binary may or may not be available at run-time via the reflective libraries of the Java platform." This commit lowers the log level of these messages from warn to debug, but leaves at warn level other messages dealing with the ability reflectively read enum values from within annotations. Issue: SPR-9233

            People

            • Assignee:
              Chris Beams
              Reporter:
              Minas Manthos
              Last updater:
              Trevor Marshall
            • Votes:
              6 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 47 weeks, 4 days ago

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - Not Specified
                Not Specified
                Logged:
                Time Spent - 40m
                40m