Affects: 6.2.0-SNAPSHOT

This appears to be a regression from 6.2.0-RC1.

Compilation of AOT-generated code fails for this app:

package com.example.aot_regression;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;

@SpringBootApplication
public class AotRegressionApplication {

    public static void main(String[] args) {
        SpringApplication.run(AotRegressionApplication.class, args);
    }

    @Component
    class Foo {

    }

}

The failure is:

/Users/awilkinson/dev/temp/aot-regression/build/generated/aotSources/com/example/aot_regression/AotRegressionApplication__BeanDefinitions.java:35: error: an enclosing instance that contains AotRegressionApplication.Foo is require
              .withGenerator((registeredBean, args) -> new AotRegressionApplication.Foo(args.get(0)));

The generated source is:

package com.example.aot_regression;

import org.springframework.aot.generate.Generated;
import org.springframework.beans.factory.aot.BeanInstanceSupplier;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ConfigurationClassUtils;

/**
 * Bean definitions for {@link AotRegressionApplication}.
 */
@Generated
public class AotRegressionApplication__BeanDefinitions {
  /**
   * Get the bean definition for 'aotRegressionApplication'.
   */
  public static BeanDefinition getAotRegressionApplicationBeanDefinition() {
    RootBeanDefinition beanDefinition = new RootBeanDefinition(AotRegressionApplication$$SpringCGLIB$$0.class);
    beanDefinition.setTargetType(AotRegressionApplication.class);
    ConfigurationClassUtils.initializeConfigurationClass(AotRegressionApplication.class);
    beanDefinition.setInstanceSupplier(AotRegressionApplication$$SpringCGLIB$$0::new);
    return beanDefinition;
  }

  /**
   * Bean definitions for {@link AotRegressionApplication.Foo}.
   */
  @Generated
  public static class Foo {
    /**
     * Get the bean instance supplier for 'com.example.aot_regression.AotRegressionApplication$Foo'.
     */
    private static BeanInstanceSupplier<AotRegressionApplication.Foo> getFooInstanceSupplier() {
      return BeanInstanceSupplier.<AotRegressionApplication.Foo>forConstructor(AotRegressionApplication.class)
              .withGenerator((registeredBean, args) -> new AotRegressionApplication.Foo(args.get(0)));
    }

    /**
     * Get the bean definition for 'foo'.
     */
    public static BeanDefinition getFooBeanDefinition() {
      RootBeanDefinition beanDefinition = new RootBeanDefinition(AotRegressionApplication.Foo.class);
      beanDefinition.setInstanceSupplier(getFooInstanceSupplier());
      return beanDefinition;
    }
  }
}

Downgrading to Framework 6.2.0-RC1 fixes the problem as the generated source is then the following:

package com.example.aot_regression;

import org.springframework.aot.generate.Generated;
import org.springframework.beans.factory.aot.BeanInstanceSupplier;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ConfigurationClassUtils;

/**
 * Bean definitions for {@link AotRegressionApplication}.
 */
@Generated
public class AotRegressionApplication__BeanDefinitions {
  /**
   * Get the bean definition for 'aotRegressionApplication'.
   */
  public static BeanDefinition getAotRegressionApplicationBeanDefinition() {
    RootBeanDefinition beanDefinition = new RootBeanDefinition(AotRegressionApplication.class);
    beanDefinition.setTargetType(AotRegressionApplication.class);
    ConfigurationClassUtils.initializeConfigurationClass(AotRegressionApplication.class);
    beanDefinition.setInstanceSupplier(AotRegressionApplication$$SpringCGLIB$$0::new);
    return beanDefinition;
  }

  /**
   * Bean definitions for {@link AotRegressionApplication.Foo}.
   */
  @Generated
  public static class Foo {
    /**
     * Get the bean instance supplier for 'com.example.aot_regression.AotRegressionApplication$Foo'.
     */
    private static BeanInstanceSupplier<AotRegressionApplication.Foo> getFooInstanceSupplier() {
      return BeanInstanceSupplier.<AotRegressionApplication.Foo>forConstructor()
              .withGenerator((registeredBean, args) -> registeredBean.getBeanFactory().getBean(AotRegressionApplication.class).new Foo());
    }

    /**
     * Get the bean definition for 'foo'.
     */
    public static BeanDefinition getFooBeanDefinition() {
      RootBeanDefinition beanDefinition = new RootBeanDefinition(AotRegressionApplication.Foo.class);
      beanDefinition.setInstanceSupplier(getFooInstanceSupplier());
      return beanDefinition;
    }
  }
}

Note the change in getFooInstanceSupplier from new AotRegressionApplication.Foo(args.get(0)) which fails to compile as Foo is not static to registeredBean.getBeanFactory().getBean(AotRegressionApplication.class).new Foo()) which works.

Comment From: wilkinsona

I suspect https://github.com/spring-projects/spring-framework/commit/d6e4bd7c90d239ba2db37b47d913ac461b5c72b9 may be the cause. Its commit message says "removes support for inner classes in alignment with standard core container behavior". The app above works fine without AOT with an instance of Foo being made available as a bean.