lucko / helper

A collection of utilities and extended APIs to support the rapid and easy development of Bukkit plugins.
MIT License
456 stars 87 forks source link

Use sun.misc.Unsafe to inject URLs into ClassLoaders on Java 9+ #107

Closed Revxrsal closed 3 years ago

Revxrsal commented 3 years ago

Since the Maven library features in helper are deemed broken on Java 16+, this PR adapts and utilizes SlimJar's UnsafeInjectable to inject URLs into URLClassLoaders using sun.misc.Unsafe. This solution works well on Java 9+ and can be used to get the API to work again.

Side implementation note: UnsafeURLInjector only works on Java 9+. While it is possible to make it work for Java 8 by replacing ArrayDeque with a generic Collection, and use urls as the field name for Java 8, I believe this is unnecessary since you can directly use reflections to add URLs on that version.

lucko commented 3 years ago

LGTM, thanks!