Skip to content

Test AOT processing fails if a feature name prefix is reused #30861

New issue

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

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

Already on GitHub? # to your account

Closed
sbrannen opened this issue Jul 11, 2023 · 0 comments
Closed

Test AOT processing fails if a feature name prefix is reused #30861

sbrannen opened this issue Jul 11, 2023 · 0 comments
Assignees
Labels
in: test Issues in the test module theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@sbrannen
Copy link
Member

@sbrannen sbrannen added in: test Issues in the test module type: bug A general bug theme: aot An issue related to Ahead-of-time processing labels Jul 11, 2023
@sbrannen sbrannen added this to the 6.0.12 milestone Jul 11, 2023
@sbrannen sbrannen self-assigned this Jul 11, 2023
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Jul 15, 2023
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Jul 15, 2023
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Jul 15, 2023
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 spring-projectsgh-30861
Closes spring-projectsgh-30898
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Jul 15, 2023
Prior to this commit, test AOT processing failed if a feature name for
generated class names was used for more than one ApplicationContext.

For example, when generating code for org.example.MessageService with a
"Management" feature name, the "BeanDefinitions" class was named as
follows (without a uniquely identifying TestContext###_ feature name
prefix).

org/example/MessageService__ManagementBeanDefinitions.java

When another attempt was made to generate code for the MessageService
using the same "Management" feature name, a FileAlreadyExistsException
was thrown denoting that the class/file name was already in use.

To avoid such naming collisions, this commit introduces a
TestContextGenerationContext which provides a custom implementation of
withName(String) that prepends an existing feature name (if present) to
a new feature name, thereby treating any existing feature name as a
prefix to a new, nested feature name.

Consequently, code generation for the above example now results in
unique class/file names like the following (which retain the uniquely
identifying TestContext###_ prefixes).

org/example/MessageService__TestContext002_ManagementBeanDefinitions.java
org/example/MessageService__TestContext003_ManagementBeanDefinitions.java

Closes spring-projectsgh-30861
sbrannen added a commit that referenced this issue Jul 15, 2023
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
sbrannen added a commit that referenced this issue Jul 15, 2023
In order to reduce the surface area of published APIs in the affected
classes, this commit:

- Reverts the changes made to GeneratedClasses in c354b10.

- Reverts the changes made to DefaultGenerationContext in a28ec3a.

- Makes the DefaultGenerationContext(DefaultGenerationContext, String)
  constructor protected.

- Reworks the internals of TestContextGenerationContext to align with
  the above changes.

See gh-30861
Closes gh-30895
Closes gh-30897
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
in: test Issues in the test module theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant