Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot Test cannot give a clear message but throw NPE now when @SpringBootConfiguration cannot be found #33370

Closed
lishangbu opened this issue Nov 26, 2022 · 1 comment
Labels
status: superseded An issue that has been superseded by another

Comments

@lishangbu
Copy link
Contributor

When we try spring boot test without @SpringBootConfiguration,NPE exception will occur.
Before supporting AOT,it throws IllegalStateException with message:

Unable to find a @SpringBootConfiguration, you need to use "
				+ "@ContextConfiguration or @SpringBootTest(classes=...) with your test

but now it occurs exception like this:

java.lang.NullPointerException: Cannot invoke "java.lang.Class.getName()" because "found" is null

	at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.findConfigurationClass(SpringBootTestContextBootstrapper.java:261)

I find that class is not checking null before setting aotTestAttributes :

Class<?> found = new AnnotatedClassFinder(SpringBootConfiguration.class).findFromClass(testClass);
this.aotTestAttributes.setAttribute(propertyName, found.getName());

We can avoid this with a small change by checking whether class with @SpringBootConfiguration is null in advance.We can move checking code from getOrFindConfigurationClasses to findConfigurationClass before setting aotTestAttributes

@wilkinsona
Copy link
Member

Closing in favor of #33371. Thanks for the PR, @lishangbu.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2022
@wilkinsona wilkinsona added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
3 participants