Skip to content

Reduce log level for message re: missing annotation [SPR-9233] #13871

@spring-projects-issues

Description

@spring-projects-issues

Minas Manthos opened SPR-9233 and commented

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.


Affects: 3.1.1

Sub-tasks:

Issue Links:

Referenced from: commits c25a1bc, f55a4a1

6 votes, 7 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions