Skip to content

Commit 317c6fb

Browse files
committed
Introduce failOnError flag in TestContextAotGenerator
This commit introduces a `failOnError` flag in TestContextAotGenerator. When set to `true`, any error encountered during AOT processing will result in an exception that fails the overall process. When set to `false` (the default), the previous behavior remains unchanged: a DEBUG or WARN message will be logged, and processing will continue. This feature is currently only used for internal testing. See gh-30861 Closes gh-30898
1 parent c354b10 commit 317c6fb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public class TestContextAotGenerator {
8585

8686
private final RuntimeHints runtimeHints;
8787

88+
private final boolean failOnError;
89+
8890

8991
/**
9092
* Create a new {@link TestContextAotGenerator} that uses the supplied
@@ -102,9 +104,23 @@ public TestContextAotGenerator(GeneratedFiles generatedFiles) {
102104
* @param runtimeHints the {@code RuntimeHints} to use
103105
*/
104106
public TestContextAotGenerator(GeneratedFiles generatedFiles, RuntimeHints runtimeHints) {
107+
this(generatedFiles, runtimeHints, false);
108+
}
109+
110+
/**
111+
* Create a new {@link TestContextAotGenerator} that uses the supplied
112+
* {@link GeneratedFiles}, {@link RuntimeHints}, and {@code failOnError} flag.
113+
* @param generatedFiles the {@code GeneratedFiles} to use
114+
* @param runtimeHints the {@code RuntimeHints} to use
115+
* @param failOnError {@code true} if errors encountered during AOT processing
116+
* should result in an exception that fails the overall process
117+
* @since 6.0.12
118+
*/
119+
TestContextAotGenerator(GeneratedFiles generatedFiles, RuntimeHints runtimeHints, boolean failOnError) {
105120
this.testRuntimeHintsRegistrars = AotServices.factories().load(TestRuntimeHintsRegistrar.class);
106121
this.generatedFiles = generatedFiles;
107122
this.runtimeHints = runtimeHints;
123+
this.failOnError = failOnError;
108124
}
109125

110126

@@ -210,6 +226,10 @@ private MultiValueMap<ClassName, Class<?>> processAheadOfTime(
210226
generationContext.writeGeneratedContent();
211227
}
212228
catch (Exception ex) {
229+
if (this.failOnError) {
230+
throw new IllegalStateException("Failed to generate AOT artifacts for test classes " +
231+
testClasses.stream().map(Class::getName).toList(), ex);
232+
}
213233
if (logger.isDebugEnabled()) {
214234
logger.debug("Failed to generate AOT artifacts for test classes " +
215235
testClasses.stream().map(Class::getName).toList(), ex);

0 commit comments

Comments
 (0)