Skip to content

BeanRegistrationCodeFragments#getTarget does not take private class into account #29168

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

Closed
snicoll opened this issue Sep 19, 2022 · 3 comments
Closed
Labels
status: declined A suggestion or change that we don't feel we should currently apply theme: aot An issue related to Ahead-of-time processing type: bug A general bug

Comments

@snicoll
Copy link
Member

snicoll commented Sep 19, 2022

A BeanDefinition can have a constructor argument or property value of type Class. If the class reference is not public, this leads to issues as the following:

Unable to compile generated source
[ERROR] com.example.demo.DemoControllerTests is not public in com.example.demo; cannot be accessed from outside package /Users/snicoll/workspace/demos/demo-aot-native/target/spring-aot/test/sources/org/springframework/boot/test/context/ImportsContextCustomizer_ImportsCleanupPostProcessor__TestContext001_BeanDefinitions.java 3:24
[ERROR] com.example.demo.DemoControllerTests is not public in com.example.demo; cannot be accessed from outside package /Users/snicoll/workspace/demos/demo-aot-native/target/spring-aot/test/sources/org/springframework/boot/test/context/ImportsContextCustomizer_ImportsCleanupPostProcessor__TestContext001_BeanDefinitions.java 29:78

There can be issues where several privileges are required, which are impossible to fix so I am not sure what we should be doing. In this particular case, it turns out the FQN of the class is all that we need.

@snicoll snicoll added type: bug A general bug theme: aot An issue related to Ahead-of-time processing labels Sep 19, 2022
@snicoll snicoll added this to the 6.0.x milestone Sep 19, 2022
@snicoll snicoll changed the title BeanRegistrationCodeFragments#getTarget does not take parameter names into account BeanRegistrationCodeFragments#getTarget does not take private class into account Sep 19, 2022
@sdeleuze sdeleuze modified the milestones: 6.0.x, 6.1.x Feb 21, 2023
@snicoll
Copy link
Member Author

snicoll commented Oct 17, 2023

It would be nice to be able to know where the code is generated and offers some escape hatch. In this case, we could generate code that would load the class at runtime via ClassUtils

@snicoll snicoll modified the milestones: 6.1.x, 6.2.x Oct 23, 2023
@snicoll
Copy link
Member Author

snicoll commented Oct 23, 2023

The contract created by #28999 could mean we'd be able to improve the ClassDelegate so that it uses ReflectionUtils#resolveClassName for cases where the Class is not accessible in the curent context.

@snicoll
Copy link
Member Author

snicoll commented Apr 30, 2024

I am not sure we should change the code just yet. The sample I've created was a bit contrived and it would be impossible to recreate this setup with manual code which is something that we're trying to make an assumption for AOT.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2024
@snicoll snicoll removed this from the 6.2.x milestone Apr 30, 2024
@snicoll snicoll added the status: declined A suggestion or change that we don't feel we should currently apply label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants