Skip to content

Commit d232636

Browse files
committed
Improve exception message when configuration class parsing fails
This commit improves the exception that is thrown when a particular source class cannot be parsed. Previously, the message would include the root configuration class, which may not be the class that actually failed as parsing can trigger component scan. There's now a dedicated catch that generates an exception message that includes the class that is currently parsed. Closes gh-31146
1 parent a71eb3f commit d232636

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,18 @@ protected void processConfigurationClass(ConfigurationClass configClass, Predica
238238
}
239239

240240
// Recursively process the configuration class and its superclass hierarchy.
241-
SourceClass sourceClass = asSourceClass(configClass, filter);
242-
do {
243-
sourceClass = doProcessConfigurationClass(configClass, sourceClass, filter);
241+
SourceClass sourceClass = null;
242+
try {
243+
sourceClass = asSourceClass(configClass, filter);
244+
do {
245+
sourceClass = doProcessConfigurationClass(configClass, sourceClass, filter);
246+
}
247+
while (sourceClass != null);
248+
}
249+
catch (IOException ex) {
250+
throw new BeanDefinitionStoreException(
251+
"I/O failure while processing configuration class [" + sourceClass + "]", ex);
244252
}
245-
while (sourceClass != null);
246253

247254
this.configurationClasses.put(configClass, configClass);
248255
}

0 commit comments

Comments
 (0)