The following error occurs during the processAot
Gradle task when attempting to build a large project of mine with Spring Boot 3.0.0 (with the native plugin applied):
Exception in thread "main" java.lang.IllegalArgumentException: invalid type parameter: boolean
at org.springframework.javapoet.Util.checkArgument(Util.java:53)
at org.springframework.javapoet.ParameterizedTypeName.<init>(ParameterizedTypeName.java:51)
at org.springframework.javapoet.ParameterizedTypeName.<init>(ParameterizedTypeName.java:38)
at org.springframework.javapoet.ParameterizedTypeName.get(ParameterizedTypeName.java:119)
at org.springframework.beans.factory.aot.InstanceSupplierCodeGenerator.buildGetInstanceMethodForFactoryMethod(InstanceSupplierCodeGenerator.java:247)
at org.springframework.beans.factory.aot.InstanceSupplierCodeGenerator.lambda$generateCodeForAccessibleFactoryMethod$2(InstanceSupplierCodeGenerator.java:221)
at org.springframework.aot.generate.GeneratedMethod.<init>(GeneratedMethod.java:54)
at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:112)
at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:89)
at org.springframework.beans.factory.aot.InstanceSupplierCodeGenerator.generateGetInstanceSupplierMethod(InstanceSupplierCodeGenerator.java:318)
at org.springframework.beans.factory.aot.InstanceSupplierCodeGenerator.generateCodeForAccessibleFactoryMethod(InstanceSupplierCodeGenerator.java:220)
at org.springframework.beans.factory.aot.InstanceSupplierCodeGenerator.generateCodeForFactoryMethod(InstanceSupplierCodeGenerator.java:202)
at org.springframework.beans.factory.aot.InstanceSupplierCodeGenerator.generateCode(InstanceSupplierCodeGenerator.java:100)
at org.springframework.beans.factory.aot.DefaultBeanRegistrationCodeFragments.generateInstanceSupplierCode(DefaultBeanRegistrationCodeFragments.java:206)
at org.springframework.beans.factory.aot.BeanRegistrationCodeGenerator.generateCode(BeanRegistrationCodeGenerator.java:89)
at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.lambda$generateBeanDefinitionMethod$3(BeanDefinitionMethodGenerator.java:186)
at org.springframework.aot.generate.GeneratedMethod.<init>(GeneratedMethod.java:54)
at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:112)
at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:89)
at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.generateBeanDefinitionMethod(BeanDefinitionMethodGenerator.java:180)
at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.generateBeanDefinitionMethod(BeanDefinitionMethodGenerator.java:102)
at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.lambda$generateRegisterBeanDefinitionsMethod$2(BeanRegistrationsAotContribution.java:85)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:729)
at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.generateRegisterBeanDefinitionsMethod(BeanRegistrationsAotContribution.java:83)
at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.lambda$applyTo$1(BeanRegistrationsAotContribution.java:67)
at org.springframework.aot.generate.GeneratedMethod.<init>(GeneratedMethod.java:54)
at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:112)
at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:89)
at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.applyTo(BeanRegistrationsAotContribution.java:66)
at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:78)
at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58)
at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106)
at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82)
at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:76)
How does one go about debugging this further? It seems this error occurs when attempting to generate a bean definition, but I have no idea which bean is causing the issue, nor how to identify it from this stacktrace.
Thanks 😃
Environment:
------------------------------------------------------------
Gradle 7.6
------------------------------------------------------------
Build time: 2022-11-25 13:35:10 UTC
Revision: daece9dbc5b79370cc8e4fd6fe4b2cd400e150a8
Kotlin: 1.7.10
Groovy: 3.0.13
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 19.0.1 (GraalVM Community 19.0.1+10-jvmci-22.3-b08)
OS: Windows 10 10.0 amd64
Comment From: mhalbritter
Hey, could you provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem?
Comment From: jhg023
I was able to narrow down the issue to a bean in one of my dependencies (which I also own). It turns out to be caused by this (written in Kotlin):
@Configuration
class EnvironmentConfig @Autowired constructor(
private val environment: Environment
) {
private fun acceptsProfile(profile: String): Boolean = environment.acceptsProfiles(Profiles.of(profile))
@Bean
@Qualifier("isDevProfile")
fun isDevProfile(): Boolean = acceptsProfile("dev")
@Bean
@Qualifier("isLocalProfile")
fun isLocalProfile(): Boolean = acceptsProfile("local")
@Bean
@Qualifier("isProdProfile")
fun isProdProfile(): Boolean = acceptsProfile("prod")
}
Comment From: jhg023
I simplified the class to this, and the same error still occurs (both with and without @Qualifier
):
@Configuration
class EnvironmentConfig {
@Bean
@Qualifier("someBoolean")
fun someBoolean(): Boolean = true
}
Comment From: jhg023
Changing Boolean
to Int
results in a similar error message: java.lang.IllegalArgumentException: invalid type parameter: int
I suppose this is happening for all primitive types 🤔
Comment From: jhg023
I've found that using a nullable type (Boolean?
vs Boolean
) resolves the issue, but this seems undesirable for beans meant to be non-null.
Comment From: wilkinsona
I suppose this is happening for all primitive types
I suspect so.
I don't think I've ever seen a Boolean
bean before. The most "plain" that I've seen in a String
. That said, as it works normally, I think we should aim for it to work with an AOT-processed context as well. The code in question is part of Spring Framework so we'll transfer this issue to the Framework repository.
Comment From: jhg023
Thank you, I appreciate it!