Use LauncherInterceptor for JUnit tests#4226
Conversation
| } | ||
| final ModuleFinder spongeFinder = this.createModuleFinder(spongeJars); | ||
| final ModuleFinder resourceFinder = this.createModuleFinder(resourceJars); | ||
| parentLoader = new FilteringPassthroughClassLoader(contextLoader, |
There was a problem hiding this comment.
This ensures that the classes that are supposed to be inside the module layers are not loaded through the bootstrap layer as we are now exposing a hole that can access the application class loader and thus gain access to the original classpath. Classes that we don't end up loading inside the module layers are still accessible and fallback to the parent.
| urls[i] = resourcePaths.get(i).toUri().toURL(); | ||
| } | ||
| parentLoader = new URLClassLoader("BOOTSTRAP-RESOURCES", urls, parentLoader); | ||
| parentLoader = new ResourceClassLoader("BOOTSTRAP-RESOURCES", urls, parentLoader); |
There was a problem hiding this comment.
Same here, this could cause class loading from the resources we just provided outside of the module layers.
|
|
||
| @Override | ||
| protected Class<?> findClass(final String name) throws ClassNotFoundException { | ||
| throw new ClassNotFoundException(name); |
There was a problem hiding this comment.
This rejects all class loading that failed to be fetched from the parent.
|
LGTM! See https://github.com/Yeregorix/AutoPickup/blob/feature/unit-tests/build.gradle#L71 for a POC. In the long term, I plan to pre-configure everything in SpongeGradle. |
We are now guaranteed to be in the transforming class loader during unit test loading and their execution, ensuring class loading happens from the correct
ClassLoader.