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

Suppress deprecation warning for AOT-generated code that refers to a deprecated member #29597

Closed
akefirad opened this issue Nov 15, 2022 · 5 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@akefirad
Copy link

And probably other generated BeanDefinitions by AoT?
Example:

    public static BeanDefinition getThemeResolverBeanDefinition() {
      Class<?> beanType = ThemeResolver.class;
      RootBeanDefinition beanDefinition = new RootBeanDefinition(beanType);
      beanDefinition.setInstanceSupplier(getThemeResolverInstanceSupplier());
      return beanDefinition;
    }
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 15, 2022
@snicoll
Copy link
Member

snicoll commented Nov 15, 2022

What is the benefit of suppressing the deprecation automatically? I don't think we should be doing that for generated code.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Nov 15, 2022
@akefirad
Copy link
Author

akefirad commented Nov 15, 2022

Well, the code is generated by the library, so there's no way for me to suppress it. That means we'd see the warning during compilation. I guess this would be an issue wherever the source code is used (e.g. code analysis tools maybe? if they look at the generated code as well)

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 15, 2022
@snicoll
Copy link
Member

snicoll commented Nov 15, 2022

Yes, I understand that. I don't think your code analysis tool should be looking at generated code. In the absence of an actual problem, I am going to close this. I understand that the warning can be annoying but blindly (automatically) suppressing it is worse IMO.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2022
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Nov 15, 2022
@wilkinsona
Copy link
Member

We discussed this today and we think that there would be some value in the generated code not producing any compilation warnings. The warnings aren't helpful as the user can't do anything to the generated code to fix them.

We could configure Boot to compile the code with -Xlint:none but the warnings will still be present when viewed in an IDE. To avoid them entirely, @SuppressWarnings would have to be generated at build time. This would have to be done in Spring Framework where the code generation is performed. We'll transfer this issue to Framework for their consideration.

@wilkinsona wilkinsona reopened this Nov 28, 2022
@wilkinsona wilkinsona added status: waiting-for-triage An issue we've not yet triaged or decided on and removed status: declined A suggestion or change that we don't feel we should currently apply for: team-meeting labels Nov 28, 2022
@bclozel bclozel transferred this issue from spring-projects/spring-boot Nov 28, 2022
@bclozel bclozel added type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 29, 2022
@bclozel bclozel added this to the 6.0.x milestone Nov 29, 2022
@bclozel bclozel added type: bug A general bug and removed type: enhancement A general enhancement labels Nov 29, 2022
@sdeleuze sdeleuze modified the milestones: 6.0.x, 6.1.x Jul 4, 2023
@wilkinsona
Copy link
Member

wilkinsona commented Oct 9, 2023

This is quite noticeable in Spring Boot 3.2 as almost every app with see at least these deprecation warnings when compiling the AOT-generated code:

> Task :data:hateoas:compileAotJava
/Users/awilkinson/dev/spring-projects/spring-aot-smoke-tests/data/hateoas/build/generated/aotSources/org/springframework/boot/autoconfigure/task/TaskExecutorConfigurations__BeanDefinitions.java:32: warning: [removal] TaskExecutorBuilder in org.springframework.boot.task has been deprecated and marked for removal
    private static BeanInstanceSupplier<TaskExecutorBuilder> getTaskExecutorBuilderInstanceSupplier(
                                        ^
/Users/awilkinson/dev/spring-projects/spring-aot-smoke-tests/data/hateoas/build/generated/aotSources/org/springframework/boot/autoconfigure/task/TaskExecutorConfigurations__BeanDefinitions.java:34: warning: [removal] TaskExecutorBuilder in org.springframework.boot.task has been deprecated and marked for removal
      return BeanInstanceSupplier.<TaskExecutorBuilder>forFactoryMethod(TaskExecutorConfigurations.TaskExecutorBuilderConfiguration.class, "taskExecutorBuilder", TaskExecutionProperties.class, ObjectProvider.class, ObjectProvider.class)
                                   ^
/Users/awilkinson/dev/spring-projects/spring-aot-smoke-tests/data/hateoas/build/generated/aotSources/org/springframework/boot/autoconfigure/task/TaskExecutorConfigurations__BeanDefinitions.java:35: warning: [removal] taskExecutorBuilder(TaskExecutionProperties,ObjectProvider<TaskExecutorCustomizer>,ObjectProvider<TaskDecorator>) in TaskExecutorBuilderConfiguration has been deprecated and marked for removal
              .withGenerator((registeredBean, args) -> registeredBean.getBeanFactory().getBean(TaskExecutorConfigurations.TaskExecutorBuilderConfiguration.class).taskExecutorBuilder(args.get(0), args.get(1), args.get(2)));
                                                                                                                                                                 ^
/Users/awilkinson/dev/spring-projects/spring-aot-smoke-tests/data/hateoas/build/generated/aotSources/org/springframework/boot/autoconfigure/task/TaskExecutorConfigurations__BeanDefinitions.java:43: warning: [removal] TaskExecutorBuilder in org.springframework.boot.task has been deprecated and marked for removal
      beanDefinition.setTargetType(TaskExecutorBuilder.class);
                                   ^
/Users/awilkinson/dev/spring-projects/spring-aot-smoke-tests/data/hateoas/build/generated/aotSources/org/springframework/boot/autoconfigure/task/TaskExecutorConfigurations__BeanDefinitions.java:67: warning: [removal] TaskExecutorBuilder in org.springframework.boot.task has been deprecated and marked for removal
      return BeanInstanceSupplier.<ThreadPoolTaskExecutor>forFactoryMethod(TaskExecutorConfigurations.TaskExecutorConfiguration.class, "applicationTaskExecutor", TaskExecutorBuilder.class, ObjectProvider.class)
                                                                                                                                                                  ^
/Users/awilkinson/dev/spring-projects/spring-aot-smoke-tests/data/hateoas/build/generated/aotSources/org/springframework/boot/autoconfigure/task/TaskSchedulingConfigurations__BeanDefinitions.java:64: warning: [removal] TaskSchedulerBuilder in org.springframework.boot.task has been deprecated and marked for removal
    private static BeanInstanceSupplier<TaskSchedulerBuilder> getTaskSchedulerBuilderInstanceSupplier(
                                        ^
/Users/awilkinson/dev/spring-projects/spring-aot-smoke-tests/data/hateoas/build/generated/aotSources/org/springframework/boot/autoconfigure/task/TaskSchedulingConfigurations__BeanDefinitions.java:66: warning: [removal] TaskSchedulerBuilder in org.springframework.boot.task has been deprecated and marked for removal
      return BeanInstanceSupplier.<TaskSchedulerBuilder>forFactoryMethod(TaskSchedulingConfigurations.TaskSchedulerBuilderConfiguration.class, "taskSchedulerBuilder", TaskSchedulingProperties.class, ObjectProvider.class)
                                   ^
/Users/awilkinson/dev/spring-projects/spring-aot-smoke-tests/data/hateoas/build/generated/aotSources/org/springframework/boot/autoconfigure/task/TaskSchedulingConfigurations__BeanDefinitions.java:75: warning: [removal] TaskSchedulerBuilder in org.springframework.boot.task has been deprecated and marked for removal
      beanDefinition.setTargetType(TaskSchedulerBuilder.class);
                                   ^
Note: /Users/awilkinson/dev/spring-projects/spring-aot-smoke-tests/data/hateoas/build/generated/aotSources/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration__BeanDefinitions.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
8 warnings

@snicoll snicoll self-assigned this Oct 9, 2023
@snicoll snicoll changed the title Suppress Deprecation Warning in WebMvcAutoConfiguration__BeanDefinitions Class Suppress Deprecation Warning for AOT-generated code that refers to a deprecated member Oct 9, 2023
@sbrannen sbrannen changed the title Suppress Deprecation Warning for AOT-generated code that refers to a deprecated member Suppress deprecation warning for AOT-generated code that refers to a deprecated member Oct 9, 2023
snicoll added a commit to snicoll/spring-framework that referenced this issue Oct 10, 2023
This commit is a prerequisite to help suppressing deprecating warnings
by allowing tests to validate that the compiler does not encounter them.

See spring-projectsgh-29597
@snicoll snicoll modified the milestones: 6.1.x, 6.1.0-RC1 Oct 10, 2023
snicoll added a commit that referenced this issue Oct 10, 2023
This commit is a prerequisite to help suppressing deprecating warnings
by allowing tests to validate that the compiler does not encounter them.

See gh-29597
snicoll added a commit that referenced this issue Oct 10, 2023
This commit is a best effort attempt at identifying the members that
code generation invokes and might be deprecated. It introduces
a CodeWarnings helper class that records warnings, with special
handling for `@Deprecated`.

See gh-29597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants