In 0288878 to resolve gh-22409, a little bug was introduced: if there is LinkageError in FactoryBean instantiation, no first exception.

In JVM, if a class cannot be initialized, it acts like this: - at the first time, it will show the real reason and stack - then, only show "NoClassDefFoundError: Could not initialize class xxx"

Comment From: pivotal-issuemaster

@liudongmiao Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-issuemaster

@liudongmiao Thank you for signing the Contributor License Agreement!

Comment From: liudongmiao

@jhoeller

Even the exception is recorded by onSuppressedException, however, the suppressedExceptions can be cleard without be added into relatedCause.

https://github.com/spring-projects/spring-framework/blob/4e54c25179e38c235bfba1dfca93ebe350e247c0/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java#L229-L258

Sometimes recordSuppressedExceptions is false, and suppressedExceptions is not Empty, then it's been cleared without call addRelatedCause.

Even if I call addRelatedCause or don't clear suppressedExceptions, the log is confused. Then I try every version from spring 4.2 to latest, find the affected version, and finally the commit 0288878.

Comment From: jhoeller

I went with a custom ex.contains(LinkageError.class) check for the FactoryBean part, reusing some of your test code (with an author attribution). I left the PropertyAccessor part as-is since the initial exception does not really disappear there, it's rather the log output being somewhat complex there... due to the property batch update mechanism which should not get bypassed. Also, such XML-driven scenarios with linkage errors in setter methods seem rather rare, not worth making compromises for.

Thanks for the pull request in any case!