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

AOT-generated code produces deprecation warnings when referencing a nested class of a deprecated class #33273

Closed
wilkinsona opened this issue Jul 25, 2024 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented Jul 25, 2024

Affects: 6.x

MockitoPostProcessor has been deprecated in Spring Boot. AOT processing of an application's tests generates code like this:

    /**
     * Get the bean definition for 'spyPostProcessor'.
     */
    public static BeanDefinition getSpyPostProcessorBeanDefinition() {
      RootBeanDefinition beanDefinition = new RootBeanDefinition(MockitoPostProcessor.SpyPostProcessor.class);
      beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
      beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, new RuntimeBeanReference("org.springframework.boot.test.mock.mockito.MockitoPostProcessor"));
      beanDefinition.setInstanceSupplier(getSpyPostProcessorInstanceSupplier());
      return beanDefinition;
    }

This results in a deprecation warning for MockitoPostProcessor.

Note that the generated code correctly suppresses warnings for using MockitoPostProcessor directly:

  /**
   * Get the bean definition for 'mockitoPostProcessor'.
   */
  @SuppressWarnings("deprecation")
  public static BeanDefinition getMockitoPostProcessorBeanDefinition() {
    RootBeanDefinition beanDefinition = new RootBeanDefinition(MockitoPostProcessor.class);
    beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, Collections.emptySet());
    beanDefinition.setInstanceSupplier(getMockitoPostProcessorInstanceSupplier());
    return beanDefinition;
  }

Referring to the SpyPostProcessor nested class appears to be enough to throw off the deprecated API detection.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 25, 2024
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing labels Jul 25, 2024
@sbrannen sbrannen changed the title AOT-generated code produces deprecation warnings when referencing a nested class of a deprecated class Suppress deprecation warnings in AOT-generated code when referencing a nested class of a deprecated class Jul 25, 2024
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 25, 2024
@sbrannen sbrannen added this to the 6.2.x milestone Jul 25, 2024
@snicoll snicoll modified the milestones: 6.2.x, 6.2.0-M7 Jul 25, 2024
@snicoll snicoll self-assigned this Jul 25, 2024
@snicoll snicoll added type: bug A general bug and removed type: enhancement A general enhancement labels Jul 25, 2024
@snicoll snicoll changed the title Suppress deprecation warnings in AOT-generated code when referencing a nested class of a deprecated class AOT-generated code produces deprecation warnings when referencing a nested class of a deprecated class Jul 25, 2024
@snicoll snicoll modified the milestones: 6.2.0-M7, 6.1.12 Jul 25, 2024
@snicoll
Copy link
Member

snicoll commented Jul 25, 2024

This is a bug of what we intended to implement in #29597. As such, the issue as originally titled sounds better to me, and it should be fixed in 6.1.x.

@wilkinsona
Copy link
Member Author

Thanks, @snicoll. A fix in 6.1.x was what I hoped for as this looked like a bug to me based on the previous work in this area in that generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants