Skip to content

Failure during test AOT processing when multiple merged context configurations result in the Logback model being written multiple times #36997

Closed
@chicobento

Description

@chicobento

Hi,

I'm getting the following error when running ./mvnw -Dspring.aot.enabled=true test :

[ERROR] com.example.testactuatornative.Test2ITTest  Time elapsed: 0.053 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load AOT ApplicationContextInitializer class for test class [com.example.testactuatornative.Test2ITTest]. This can occur if AOT processing has not taken place for the test suite. It can also occur if AOT processing failed for the test class, in which case you can consult the logs generated during AOT processing.
        at org.springframework.util.Assert.state(Assert.java:97)

This is because during ./mvnw clean test spring-boot:process-test-aot the following exception is thrown, preventing the AotTestContextInitializers from being generated for some of the IT classes:

2023-08-15T22:16:37.187Z DEBUG 2683 --- [           main] o.s.t.c.aot.TestContextAotGenerator      : Failed to generate AOT artifacts for test classes [com.example.testactuatornative.Test2ITTest]

org.springframework.test.context.aot.TestContextAotException: Failed to process test class [com.example.testactuatornative.Test2ITTest] for AOT
        at org.springframework.test.context.aot.TestContextAotGenerator.processAheadOfTime(TestContextAotGenerator.java:248)
        at org.springframework.test.context.aot.TestContextAotGenerator.lambda$processAheadOfTime$4(TestContextAotGenerator.java:206)
        at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
        at org.springframework.util.MultiValueMapAdapter.forEach(MultiValueMapAdapter.java:179)
        at org.springframework.test.context.aot.TestContextAotGenerator.processAheadOfTime(TestContextAotGenerator.java:196)
        at org.springframework.test.context.aot.TestContextAotGenerator.processAheadOfTime(TestContextAotGenerator.java:158)
        at org.springframework.test.context.aot.TestAotProcessor.performAotProcessing(TestAotProcessor.java:91)
        at org.springframework.test.context.aot.TestAotProcessor.doProcess(TestAotProcessor.java:72)
        at org.springframework.test.context.aot.TestAotProcessor.doProcess(TestAotProcessor.java:39)
        at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82)
        at org.springframework.boot.test.context.SpringBootTestAotProcessor.main(SpringBootTestAotProcessor.java:63)
Caused by: java.lang.IllegalStateException: java.nio.file.FileAlreadyExistsException: /workspaces/test-context-spring-native/target/spring-aot/test/resources/META-INF/spring/logback-model
        at org.springframework.aot.generate.FileSystemGeneratedFiles.addFile(FileSystemGeneratedFiles.java:97)
        at org.springframework.aot.generate.GeneratedFiles.addResourceFile(GeneratedFiles.java:114)
        at org.springframework.boot.logging.logback.SpringBootJoranConfigurator$ModelWriter.writeTo(SpringBootJoranConfigurator.java:176)
        at org.springframework.boot.logging.logback.SpringBootJoranConfigurator$LogbackConfigurationAotContribution.applyTo(SpringBootJoranConfigurator.java:148)
        at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:78)
        at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58)
        at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
        at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
        at org.springframework.test.context.aot.TestContextAotGenerator.processAheadOfTime(TestContextAotGenerator.java:244)
        ... 10 common frames omitted

I have tested with fw 6.0.12-SNAPSHOT containing spring-projects/spring-framework#30861 patch but the error still occurs.

Reproducing

This issue is similar to #34337 and can be reproduced when:

  • spring-cloud-context is on classpath
  • logback-spring.xml is defined
  • there are two ITs defining different SpringBoot properties

Minimal project example: https://github.com/chicobento/test-context-spring-native

Metadata

Metadata

Assignees

Labels

theme: aotAn issue related to Ahead-of-time processingtype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions