-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
GeneratedFiles#addSource does not provide proper context if the specified class name is invalid #31612
GeneratedFiles#addSource does not provide proper context if the specified class name is invalid #31612
Conversation
caf6486
to
67c7e27
Compare
@PiotrFLEURY Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
67c7e27
to
8115c43
Compare
@PiotrFLEURY Thank you for signing the Contributor License Agreement! |
@PiotrFLEURY thanks for the PR. Can you share how you ended up in that situation? |
Thank you for making your first contribution to Spring Framework, @PiotrFLEURY. Interested to understand more what caused this as there might be something else that needs fixing to prevent that from happening. |
Thanks to you @snicoll for accepting my contribution. The pull request was closed but I see that you merged polished modification on main branch. Thanks for the polishing. I will give more details as soon as I fully understand what was the root cause of the build problem. |
I finally spotted the root cause thanks to this new detailed message 🚀 It can easily reproduced. Steps to reproducestart.spring.ioGenerates a new Spring boot project using Maven + Kotlin + Graalvm native support. Required versions
CodeCreate a data class named MyConfig and ommit package directive import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
@Configuration
@ConfigurationProperties(prefix = "config")
data class MyConfig(
var apps: Map<String, String>
) Now add package com.example.demokotlinnative
import MyConfig
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.runApplication
@SpringBootApplication
@EnableConfigurationProperties(MyConfig::class)
class DemoKotlinNativeApplication
fun main(args: Array<String>) {
runApplication<DemoKotlinNativeApplication>(*args)
} Try build native imageRun IssueSpring aot processor fails with the following message Exception in thread "main" java.lang.IllegalArgumentException: 'className' must be a valid identifier, got '.MyConfig__BeanDefinitions'
at org.springframework.util.Assert.isTrue(Assert.java:122)
at org.springframework.aot.generate.GeneratedFiles.getClassNamePath(GeneratedFiles.java:164) Expected behaviorAs a missing package directive is a warning should the build pass with warning ? Or should it fail with a dedicated message asking to fix the missing package directive ?
Hope this will help @snicoll Feel free to ask for any further info |
Thanks @PiotrFLEURY. This is largely a Kotlin-specific problem as Java does not allow to import classes from the default package. I've reproduced based on your snippet above, please watch #31628 for updates. |
Context
I tried to build native Spring boot artifact and spent hours to struggle with build failed obscure error. I was not able to spot the build failed root cause because of the too generic error message
'className' must be a valid identifier
This error message prevents me to fix the problem
I did not found any related issue to this specific point.
Observation
GeneratedFiles.getClassNamePath(String className)
error message is too genericProposal
Put className value in the error message