Fix file leak in ClassLoaderUtilsIntegrationTest
09 Sep 18 b4d3bf2323cf5d09cfc1328a13ac0769fa350a40
Separate defineClass and decorateClass (#6028)
After https://github.com/gradle/gradle/pull/5811 is merged, I was surprised that the illegal reflective access warnings still appear:
> Illegal reflective access using Lookup on org.gradle.internal.classloader.ClassLoaderUtils
It turns out that a lookup object which is accessible to the target class class loader must be provided. For example, if we want to invoke `MyClassLoader.defineClass` via `Lookup`, we must provide a lookup object from `privateLookupIn(MyClassLoader.class)`, not `privateLookupIn(ClassLoader.class)`. Otherwise, we'll get the warning and potential failure in the future.
See more information in the https://mydailyjava.blogspot.com/2018/04/jdk-11-and-proxies-in-world-past.html
Also, this PR does a tiny improvement: it uses `Lookup.defineClass` as much as possible. `Lookup.defineClass` is expected to replace `Unsafe.defineClass` by JDK team, but `Lookup.defineClass` has a limitation: it can only `defines a class to the same class loader and in the same runtime package and protection domain as this lookup's lookup class`. If we're decorating a class, this is gonna be fine and we use this API, otherwise we use `Lookup` to invoke `ClassLoader.defineClass` as a fallback.
19 Jul 18 dbc39fecff7793c4dfa9ff21457a8558167008ea