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

Likely issues of incorrect classloader being used #27134

Closed
jaminh opened this issue Jul 1, 2021 · 5 comments
Closed

Likely issues of incorrect classloader being used #27134

jaminh opened this issue Jul 1, 2021 · 5 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@jaminh
Copy link
Contributor

jaminh commented Jul 1, 2021

I found additional places in the code that look like they likely could cause issues when an alternate classloader is used for a SpringApplication, but I have not actually experienced an issue yet.

if (ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", null)) {

return ClassUtils.isPresent("org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory", null);

return ClassUtils.resolveClassName(target, null).isAssignableFrom(type);

Class<?> interpolatorClass = ClassUtils.resolveClassName(fallback, null);

Class<?> initializerClass = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());

Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 1, 2021
@philwebb philwebb added for: team-meeting An issue we'd like to discuss as a team to make progress type: bug A general bug and removed for: team-meeting An issue we'd like to discuss as a team to make progress status: waiting-for-triage An issue we've not yet triaged labels Jul 2, 2021
@philwebb philwebb added this to the 2.6.x milestone Jul 7, 2021
@philwebb
Copy link
Member

philwebb commented Jul 7, 2021

Also

Similar to issues #27071 and #27072 the YamlPropertySourceLoader does not use an alternate classloader if one is provided to the SpringApplication. The problem can be found here

.

@wilkinsona
Copy link
Member

Thanks for this. While a number of these look similar to #27133, there are others where someone may be relying on the current behaviour. Until someone reports a concrete problem we'd prefer to leave things as they are and avoid the risk of introducing a subtle regression.

@wilkinsona wilkinsona removed this from the 2.4.x milestone Jul 20, 2021
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed type: bug A general bug labels Jul 20, 2021
@ArthurEnglebert
Copy link

Hello, not sure if related, but today, we got a problem related to autowiring features only occuring when using devtools.
The autowiring works correctly if the application is launched inside a tomcat, or as a runnable jar.
On the other hand, when used with the devtools restart system (spring-boot:run / intellij spring-boot configuration), the autowiring fails to map the correct beans together.

Here is what I found so far (sorry for the hidden information, as this is a company application, i cannot show you some parts of the code).

bug-classloader_LI

Backstory of the code is :
Standard autowiring feature (via @Autowired on a property inside a @service class scanned).
the interface maps to a bean declared in a @AutoCONFIG which is loaded (we can see it in the beanfactory).

But in the process, when the DefaultListableBeanFactory tries to find matching bean corresponding to the property interface, it fails to do so :
The exact problem is org.springframework.beans.factory.support.AbstractBeanFactory#isTypeMatch(java.lang.String, org.springframework.core.ResolvableType)

This will find both the same classes but loaded in a distinct classloader (and thus the call org.springframework.util.ClassUtils#isAssignable return false)

@wilkinsona
Copy link
Member

wilkinsona commented Aug 10, 2021

@ArthurEnglebert That’s unrelated to the changes proposed in this issue. Your problem sounds like it’s related to Devtools’ split class loader which will load frequently-changing application classes in its restart class loader and the application’s dependencies in the system class loader. I can’t say more about what may be causing your problem from what you’ve shared this far. If you’d like us to take another look, please open a new issue and provide a minimal sample (it doesn’t have to be your actual application) that reproduces the problem.

@ArthurEnglebert
Copy link

@wilkinsona well, it's probably linked to some shady underlying system IntelliJ is using as it was the very first time we had the error, and it's working well & as intented for other apps (using the same autoconfig).
If I ever get the time to cleanup the code and make a valid sample reproducing the problem, I will post that as a new issue.

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
Projects
None yet
Development

No branches or pull requests

5 participants