Snip of trace logging showing NullPointerException for spring-boot 2.7.5
15:18:20.020 [main] INFO o.s.b.d.FailureAnalyzersTest - No active profile set, falling back to 1 default profile: "default"
15:18:21.368 [main] TRACE o.s.b.diagnostics.FailureAnalyzers - Skipping org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer: liquibase/exception/ChangeLogParseException
15:18:21.371 [main] TRACE o.s.b.diagnostics.FailureAnalyzers - FailureAnalyzer null failed
java.lang.NullPointerException: null
at org.springframework.boot.diagnostics.FailureAnalyzers.analyze(FailureAnalyzers.java:124)
at org.springframework.boot.diagnostics.FailureAnalyzers.reportException(FailureAnalyzers.java:117)
at org.springframework.boot.diagnostics.FailureAnalyzersTest.<init>(FailureAnalyzersTest.java:16)
at org.springframework.boot.diagnostics.FailureAnalyzersTest$$EnhancerBySpringCGLIB$$a0584ab9.<init>(<generated>)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
Small app without liquidbase in the classpath.
package org.springframework.boot.diagnostics;
import java.util.List;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication()
public class FailureAnalyzersTest {
public FailureAnalyzersTest(ConfigurableApplicationContext context) {
List<String> classNames = List.of(
"org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer");
FailureAnalyzers failureAnalyzers = new FailureAnalyzers(context, classNames);
// failreAnalyzers.analyzers contains a null list item which prevents reporting of actual exception
failureAnalyzers.reportException(new RuntimeException("REPORT_THIS"));
}
public static void main(String[] args) {
new SpringApplication(FailureAnalyzersTest.class).run(args);
}
}
Comment From: wilkinsona
Thanks for the report. Unfortunately, I don't understand the problem. It's expected that a FailureAnalyzer implementation may fail. The exception that you've shown above is logged at trace level and then all the remaining analysers should still be called:
https://github.com/spring-projects/spring-boot/blob/f44531a7a2cd9fbd5d521afa62b6dbe828f72c22/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java#L121-L134
Can you please provide a complete yet minimal example that shows the reporting of the actual exception being prevented? Such a sample should not rely on package-private Spring Boot internals.
Comment From: mgeorge-nmdp
analyzer is null on line 124 which throws a NullPointerException that is reported only at TRACE level. The real RuntimeException("REPORT_THIS") is not in the logs at all.
A simple null check on analyzer or removing nulls from the list will resolve the bug.
Comment From: wilkinsona
The real RuntimeException("REPORT_THIS") is not in the logs at all
That is to be expected as it is not the job of FailureAnalyzers to log the exception. The caller of reportException should do that when the registered analyzers did not produce any analysis. This is what SpringApplication does:
https://github.com/spring-projects/spring-boot/blob/c8679184c18360e9af8300354cf5ab2c6dafdb1b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java#L807-L823
A simple null check on analyzer or removing nulls from the list will resolve the bug
It's not yet clear to me that there is a bug to be resolved. As I said above, please provide a complete yet minimal example that shows the actual exception not appearing in the logs without using package-private API.
Comment From: mgeorge-nmdp
Thanks for your comments.
I now see that there is no functional issue. There is just an extra stack trace in logs with no useful information.