Skip to content

Do not swallow exception cause when context refresh fails [SPR-17549] #22081

Closed as not planned
@spring-projects-issues

Description

@spring-projects-issues

Jake Robb opened SPR-17549 and commented

I have a bean that is failing to initialize and throwing an exception. The cause of the cause of the cause of that exception is the real, underlying issue.

The exception propagates to AbstractApplicationContext.refresh, at which point it is logged as a warning:

if (logger.isWarnEnabled()) {
   logger.warn("Exception encountered during context initialization - " +
         "cancelling refresh attempt: " + ex);
}

Note that the exception is being string-concatenated (and therefore toString'd), rather than passing the exception itself to the logger. This means that only the exception's type and message get written to the log, which in turn means that I only learn that my bean failed to initialize, but not why. It also means I get no stacktrace.

The fix here is to replace the + with a ,. I'll be submitting a pull request shortly.


Affects: 5.0.4, 5.0.11

Issue Links:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions