spring-projects / spring-projects/spring-framework

AOT generated BeanDefinitions contain compiler warnings

Open
#35,333 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

in: core status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

When using the org.graalvm.buildtools.native Gradle plugin and enabling the -Werror, -Xlint:all compiler flags, the build fails to compile. My company has a policy of enforcing no compilation warnings hence why we set those flags so we can proactively fix any warnings and have a clean build.

The errors seem to occur in AOT generated code to create various BeanDefinitions. Some of the beans being created may be parameterized but the generated code does not specify the generic parameters so we get unchecked and rawtypes errors. It's probably difficult to supply the actual generic params so potentially the fix may be as easy as adding @SuppressWarnings({"rawtypes", "unchecked"}) to the generated classes.

Reproduction repo: https://github.com/steven-sheehy/generated-errors
Spring Boot: 3.5.4
Spring Framework: 6.2.9
JDK: 21

Execution failed for task ':compileAotJava'.
> Compilation failed; see the compiler output below.
  error: warnings found and -Werror specified
  generated-errors/build/generated/aotSources/org/springframework/data/repository/core/support/RepositoryComposition__BeanDefinitions.java:24: warning: [rawtypes] found raw type: RepositoryFragmentsFactoryBean
      private static BeanInstanceSupplier<RepositoryFragmentsFactoryBean> getFragmentsInstanceSupplier(
                                          ^
    missing type arguments for generic class RepositoryFragmentsFactoryBean<T>
    where T is a type-variable:
      T extends Object declared in class RepositoryFragmentsFactoryBean
  generated-errors/build/generated/aotSources/org/springframework/data/repository/core/support/RepositoryComposition__BeanDefinitions.java:26: warning: [rawtypes] found raw type: RepositoryFragmentsFactoryBean
        return BeanInstanceSupplier.<RepositoryFragmentsFactoryBean>forConstructor(List.class)
                                     ^
    missing type arguments for generic class RepositoryFragmentsFactoryBean<T>
    where T is a type-variable:
      T extends Object declared in class RepositoryFragmentsFactoryBean
  generated-errors/build/generated/aotSources/org/springframework/data/repository/core/support/RepositoryComposition__BeanDefinitions.java:27: warning: [rawtypes] found raw type: RepositoryFragmentsFactoryBean
                .withGenerator((registeredBean, args) -> new RepositoryFragmentsFactoryBean(args.get(0)));
                                                             ^
    missing type arguments for generic class RepositoryFragmentsFactoryBean<T>
    where T is a type-variable:
      T extends Object declared in class RepositoryFragmentsFactoryBean
  generated-errors/build/generated/aotSources/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryBean__Autowiring.java:18: warning: [rawtypes] found raw type: JpaRepositoryFactoryBean
        JpaRepositoryFactoryBean instance) {
        ^
    missing type arguments for generic class JpaRepositoryFactoryBean<T,S,ID>
    where T,S,ID are type-variables:
      T extends Repository<S,ID> declared in class JpaRepositoryFactoryBean
      S extends Object declared in class JpaRepositoryFactoryBean
      ID extends Object declared in class JpaRepositoryFactoryBean
  generated-errors/build/generated/aotSources/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryBean__Autowiring.java:17: warning: [rawtypes] found raw type: JpaRepositoryFactoryBean
    public static JpaRepositoryFactoryBean apply(RegisteredBean registeredBean,
                  ^
    missing type arguments for generic class JpaRepositoryFactoryBean<T,S,ID>
    where T,S,ID are type-variables:
      T extends Repository<S,ID> declared in class JpaRepositoryFactoryBean
      S extends Object declared in class JpaRepositoryFactoryBean
      ID extends Object declared in class JpaRepositoryFactoryBean
  generated-errors/build/generated/aotSources/com/example/generatederrors/CustomerRepository__BeanDefinitions.java:24: warning: [rawtypes] found raw type: JpaRepositoryFactoryBean
    private static BeanInstanceSupplier<JpaRepositoryFactoryBean> getCustomerRepositoryInstanceSupplier(
                                        ^
    missing type arguments for generic class JpaRepositoryFactoryBean<T,S,ID>
    where T,S,ID are type-variables:
      T extends Repository<S,ID> declared in class JpaRepositoryFactoryBean
      S extends Object declared in class JpaRepositoryFactoryBean
      ID extends Object declared in class JpaRepositoryFactoryBean
  generated-errors/build/generated/aotSources/com/example/generatederrors/CustomerRepository__BeanDefinitions.java:26: warning: [rawtypes] found raw type: JpaRepositoryFactoryBean
      return BeanInstanceSupplier.<JpaRepositoryFactoryBean>forConstructor(Class.class)
                                   ^
    missing type arguments for generic class JpaRepositoryFactoryBean<T,S,ID>
    where T,S,ID are type-variables:
      T extends Repository<S,ID> declared in class JpaRepositoryFactoryBean
      S extends Object declared in class JpaRepositoryFactoryBean
      ID extends Object declared in class JpaRepositoryFactoryBean
  generated-errors/build/generated/aotSources/com/example/generatederrors/CustomerRepository__BeanDefinitions.java:27: warning: [rawtypes] found raw type: JpaRepositoryFactoryBean
              .withGenerator((registeredBean, args) -> new JpaRepositoryFactoryBean(args.get(0)));
                                                           ^
    missing type arguments for generic class JpaRepositoryFactoryBean<T,S,ID>
    where T,S,ID are type-variables:
      T extends Repository<S,ID> declared in class JpaRepositoryFactoryBean
      S extends Object declared in class JpaRepositoryFactoryBean
      ID extends Object declared in class JpaRepositoryFactoryBean
  generated-errors/build/generated/aotSources/com/example/generatederrors/CustomerRepository__BeanDefinitions.java:47: warning: [rawtypes] found raw type: JpaRepositoryFactoryBean
      InstanceSupplier<JpaRepositoryFactoryBean> instanceSupplier = getCustomerRepositoryInstanceSupplier();
                       ^
    missing type arguments for generic class JpaRepositoryFactoryBean<T,S,ID>
    where T,S,ID are type-variables:
      T extends Repository<S,ID> declared in class JpaRepositoryFactoryBean
      S extends Object declared in class JpaRepositoryFactoryBean
      ID extends Object declared in class JpaRepositoryFactoryBean
  generated-errors/build/generated/aotSources/org/springframework/data/repository/core/support/RepositoryComposition__BeanDefinitions.java:27: warning: [unchecked] unchecked call to RepositoryFragmentsFactoryBean(List<String>) as a member of the raw type RepositoryFragmentsFactoryBean
                .withGenerator((registeredBean, args) -> new RepositoryFragmentsFactoryBean(args.get(0)));
                                                         ^
  generated-errors/build/generated/aotSources/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryBean__Autowiring.java:19: warning: [unchecked] unchecked call to setEntityPathResolver(ObjectProvider<EntityPathResolver>) as a member of the raw type JpaRepositoryFactoryBean
      AutowiredMethodArgumentsResolver.forRequiredMethod("setEntityPathResolver", ObjectProvider.class).resolve(registeredBean, args -> instance.setEntityPathResolver(args.get(0)));
                                                                                                                                                                      ^
  generated-errors/build/generated/aotSources/com/example/generatederrors/CustomerRepository__BeanDefinitions.java:27: warning: [unchecked] unchecked call to JpaRepositoryFactoryBean(Class<? extends T>) as a member of the raw type JpaRepositoryFactoryBean
              .withGenerator((registeredBean, args) -> new JpaRepositoryFactoryBean(args.get(0)));
                                                       ^
    where T,S,ID are type-variables:
      T extends Repository<S,ID> declared in class JpaRepositoryFactoryBean
      S extends Object declared in class JpaRepositoryFactoryBean
      ID extends Object declared in class JpaRepositoryFactoryBean
  1 error
  12 warnings

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure in the linked generated-errors repository by running the compileAotJava task with -Werror and -Xlint:all. Inspect the generated RepositoryComposition__BeanDefinitions.java, JpaRepositoryFactoryBean__Autowiring.java, and CustomerRepository__BeanDefinitions.java files; done means AOT compilation completes without rawtypes or unchecked warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.