Created
February 1, 2018 16:50
-
-
Save awwsmm/792239ac90cc72a757fd6381c8395ee4 to your computer and use it in GitHub Desktop.
Disable "illegal reflective access" warnings in JDK 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Field; | |
import sun.misc.Unsafe; | |
public class DisableReflectiveAccessWarning { | |
///=========================================================================== | |
/// disableWarning(): | |
/// disable "illegal reflective access" warnings in JDK 9 | |
/// author: http://bit.ly/2FblrHA (apangin on StackOverflow) | |
/// source: http://bit.ly/2DCIsH2 | |
///=========================================================================== | |
private static void disableWarning() { | |
try { | |
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); | |
theUnsafe.setAccessible(true); | |
Unsafe u = (Unsafe) theUnsafe.get(null); | |
Class cls = Class.forName("jdk.internal.module.IllegalAccessLogger"); | |
Field logger = cls.getDeclaredField("logger"); | |
u.putObjectVolatile(cls, u.staticFieldOffset(logger), null); | |
} catch (Exception e) { | |
// ignore | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment