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

Spring Boot and Spring Data Rest - java.lang.IllegalAccessError #9911

Closed
emaysyuk opened this issue Jul 30, 2017 · 10 comments
Closed

Spring Boot and Spring Data Rest - java.lang.IllegalAccessError #9911

emaysyuk opened this issue Jul 30, 2017 · 10 comments
Labels
status: duplicate A duplicate of another issue

Comments

@emaysyuk
Copy link

emaysyuk commented Jul 30, 2017

Under WildFly 10.1.0.Final I am getting:

java.lang.IllegalAccessError: class org.springframework.data.rest.webmvc.RepositoryEntityController cannot access its superclass org.springframework.data.rest.webmvc.AbstractRepositoryRestController

This issue started to happen when I added Spring Data Rest configuration with all the necessary dependencies into the project.

I noticed that issue cannot be reproduced when I comment<context:load-time-weaver />tag inside the applicationContext.xml.

This is a sample app that reproduces the problem:
https://github.com/emaysyuk/spring-boot-data-rest

@emaysyuk emaysyuk changed the title Spring Data Rest java.lang.IllegalAccessError Spring Boot and Spring Data Rest - java.lang.IllegalAccessError Jul 30, 2017
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 30, 2017
@emaysyuk
Copy link
Author

emaysyuk commented Jul 30, 2017

I have prepared additional sample project that demonstrates that issue doesn't occur while using traditional xml configuration (without Spring Boot):

https://github.com/emaysyuk/spring-data-rest-xml-config

@emaysyuk emaysyuk changed the title Spring Boot and Spring Data Rest - java.lang.IllegalAccessError Spring Data Rest - java.lang.IllegalAccessError Jul 30, 2017
@emaysyuk emaysyuk changed the title Spring Data Rest - java.lang.IllegalAccessError Spring Boot and Spring Data Rest - java.lang.IllegalAccessError Jul 30, 2017
@philwebb
Copy link
Member

Do you have a complete stack trace from the "cannot access its superclass" error that you can attach?

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Jul 31, 2017
@wilkinsona
Copy link
Member

wilkinsona commented Jul 31, 2017

I've seen this happen in the past, but only when there are two class loaders.

When a package is defined it's associated with a particular class loader. If two class loaders define the same package they're not actually the same and anything that's package-private in a class loaded by one class loader won't be visible to a class loaded by another class loader even though the classes appear to be in the same package.

@emaysyuk
Copy link
Author

emaysyuk commented Aug 1, 2017

@philwebb
The attached file is a complete stack trace.
log.txt

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 1, 2017
@emaysyuk
Copy link
Author

emaysyuk commented Aug 1, 2017

@wilkinsona you are absolutely right.

I have found a root cause of this issue.

AbstractApplicationContext:655

At this place Spring sets ContextTypeMatchClassLoader as a temp classLoader

...

SimpleMetadataReaderFactory:98

this.resourceLoader.getClassLoader returns JBoss classLoader (not temporarily ContextTypeMatchClassLoader)

SimpleMetadataReader:63

SimpleMetadataReader passes JBoss classloader into AnnotationMetadataReadingVisitor object

AnnotationMetadataReadingVisitor:134

AnnotationMetadataReadingVisitor passes wrong class loader to AnnotationReadingVisitorUtils

AnnotationReadingVisitorUtils:78

Spring uses wrong classLoader to load org.springframework.data.rest.webmvc.RepositoryRestController and its parent org.springframework.data.rest.webmvc.AbstractRepositoryRestController and defines package for AbstractRepositoryRestController

...
ContextTypeMatchClassLoader:72

ContextTypeMatchClassLoader tries to load org.springframework.data.rest.webmvc.RepositoryEntityController and cannot find its superclass since its package has been defined using JBoss classloader

@emaysyuk
Copy link
Author

emaysyuk commented Aug 1, 2017

I think SimpleMetadataReaderFactory has to be refactored to use tempClassLoader from BeanFactory (if it is not null) and a resource class loader in other case.

@emaysyuk
Copy link
Author

emaysyuk commented Aug 1, 2017

I have found an open bug (may the same) under Spring Framework Jira:
https://jira.spring.io/browse/SPR-10206

@jhoeller
Copy link

jhoeller commented Aug 1, 2017

Let's reuse SPR-10206 for our purposes here. It does indeed hint at the same issue.

We actually intentionally use the standard ClassLoader here since we do not expect annotation types to be weaved... so we naively assumed that they can always be loaded in the factory's regular ClassLoader. It seems that this can cause conflicts with the same package split across the standard and the temp loader here?

@wilkinsona
Copy link
Member

Thanks for the analysis, @EugenMaysyuk. I'll close this one as a duplicate of SPR-10206 which I'm now watching.

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Aug 1, 2017
@shenyu1997
Copy link

I met this issue and resolve it by removing

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

6 participants