jOOQ / jOOR

jOOR - Fluent Reflection in Java jOOR is a very simple fluent API that gives access to your Java Class structures in a more intuitive way. The JDK's reflection APIs are hard and verbose to use. Other languages have much simpler constructs to access type meta information at runtime. Let us make Java reflection better.
http://www.jooq.org/products
Apache License 2.0
2.8k stars 377 forks source link

Default logic for JDK 9+ Compile ClassLoader leaks compilation internals #75

Closed lukaseder closed 5 years ago

lukaseder commented 5 years ago

The current implementation for JDK 9+'s default behaviour when all else fails is to create a new ad-hoc class loader and load the compiled byte array this way:

result = new ClassLoader() {
    @Override
    protected Class<?> findClass(String name) {
        byte[] b = fileManager.o.getBytes();
        return defineClass(className, b, 0, b.length);
    }
}.loadClass(className);

This approach using an anonymous class leaks the fileManager instance, and thus transitively other unnecessary artifacts. We only need the byte[] in this class loader.