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

Test fails with IllegalAccessError from Data JPA's proxy creation when a new context is refreshed after a test that starts Tomcat has run #6053

Closed
wilkinsona opened this issue May 27, 2016 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented May 27, 2016

https://stackoverflow.com/questions/37342590/java-lang-illegalaccesserror-when-making-spring-data-repo-package-local

The root cause is #2308. When the test that starts Tomcat (WebEnvironment.RANDOM_PORT or DEFINED_PORT) runs, the thread context class loader is set to Tomcat's web app class loader. As the context is cached, no clean up is performed after the tests are finished so the TCCL is left being Tomcat's web app class loader. This then breaks the proxy creation in a subsequent test that refreshes a new context.

We already hit another variant of the problem in #5141. We avoided it then using @DirtiesContext so that the context is closed when the tests are finished. That's not a general solution as, unlike, our integration tests where the configuration is rarely the same from test class to test class, tests for a user's application are likely to have common configuration making context caching worthwhile.

I can see two possible solutions:

  1. Revert the changes made for Set Tomcat's WebappClassLoader as the main thread's context classloader #2308
  2. Hook into the test framework so that the TCCL is configured correctly

If it's possible, 2 is the preferred option. We'd need a hook to restore the TCCL after a test class has finished and then to reinstate it before a test class runs.

@wilkinsona wilkinsona added the type: bug A general bug label May 27, 2016
@wilkinsona wilkinsona added this to the 1.4.0.RC1 milestone May 27, 2016
@wilkinsona wilkinsona self-assigned this May 27, 2016
@wilkinsona
Copy link
Member Author

I've implemented a test execution listener that manages the TCCL but it feels like a bit of a hack. I'm going to explore a third option: a different fix for #2308 so that JNDI lookups work but without us messing around with the TCCL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant