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

GeneratedFiles#addSourceFile should not allow to add a source in the default package #31628

Closed
snicoll opened this issue Nov 20, 2023 · 2 comments
Assignees
Labels
status: backported An issue that has been backported to maintenance branches theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Nov 20, 2023

When a JavaFile is added to the list of files, its class name is deduced from its package name and type name. When adding a JavaFile that was added in the default package, this leads to:

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)
        at org.springframework.aot.generate.GeneratedFiles.addSourceFile(GeneratedFiles.java:70)
        at org.springframework.aot.generate.GeneratedFiles.addSourceFile(GeneratedFiles.java:47)
        at org.springframework.aot.generate.GeneratedClasses.writeTo(GeneratedClasses.java:198)
        at org.springframework.aot.generate.DefaultGenerationContext.writeGeneratedContent(DefaultGenerationContext.java:136)
        at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:108)
        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:80)
@snicoll snicoll added type: bug A general bug theme: aot An issue related to Ahead-of-time processing labels Nov 20, 2023
@snicoll snicoll added this to the 6.0.15 milestone Nov 20, 2023
@snicoll snicoll self-assigned this Nov 20, 2023
@snicoll
Copy link
Member Author

snicoll commented Nov 20, 2023

Unfortunately, fixing the logic does not help as we can't refer to a class in the default package. So our attempt to refer to it leads to:

/Users/snicoll/Downloads/demo-kotlin-root/build/generated/aotSources/com/example/demokotlinroot/DemoKotlinRootApplicationKt__BeanFactoryRegistrations.java:46: error: cannot find symbol
    beanFactory.registerBeanDefinition("config-MyConfig", MyConfig__BeanDefinitions.getConfigMyConfigBeanDefinition());

Given we don't know the visibility of the component, we'll probably have to reject that use case upfront.

@snicoll snicoll modified the milestones: 6.0.15, 6.1.1 Nov 20, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x labels Nov 20, 2023
@snicoll snicoll changed the title GeneratedFiles#addSourceFile does not take default package into account GeneratedFiles#addSourceFile should not allow to add a source in the default package Nov 20, 2023
@snicoll
Copy link
Member Author

snicoll commented Nov 20, 2023

This throws the following now:

Exception in thread "main" java.lang.IllegalArgumentException: Could not add 'MyConfig__BeanDefinitions', processing classes in the default package is not supported. Did you forget to add a package statement?
        at org.springframework.aot.generate.GeneratedFiles.validatePackage(GeneratedFiles.java:174)
        at org.springframework.aot.generate.GeneratedFiles.addSourceFile(GeneratedFiles.java:47)
        at org.springframework.aot.generate.GeneratedClasses.writeTo(GeneratedClasses.java:198)
        at org.springframework.aot.generate.DefaultGenerationContext.writeGeneratedContent(DefaultGenerationContext.java:136)
        at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:108)
        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:80)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: backported An issue that has been backported to maintenance branches theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant