fix: ClassLoader not working with Java 9+

This commit is contained in:
danthe1st
2022-05-07 21:05:09 +02:00
parent 7a6025a278
commit 3a11e1135b
6 changed files with 26 additions and 37 deletions

View File

@@ -1,25 +1,10 @@
package app.revanced.patch
import java.io.File
import java.net.URL
import java.net.URLClassLoader
internal class PatchLoader {
internal companion object {
internal fun injectPatches(file: File) {
// This function will fail on Java 9 and above.
try {
val url = file.toURI().toURL()
val classLoader = Thread.currentThread().contextClassLoader as URLClassLoader
val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
method.isAccessible = true
method.invoke(classLoader, url)
} catch (e: Exception) {
throw Exception(
"Failed to inject patches! The CLI does NOT work on Java 9 and above, please use Java 8!",
e // propagate exception
)
}
}
}
}