Skip to content

Instantly share code, notes, and snippets.

@awwsmm
Created February 1, 2018 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awwsmm/792239ac90cc72a757fd6381c8395ee4 to your computer and use it in GitHub Desktop.
Save awwsmm/792239ac90cc72a757fd6381c8395ee4 to your computer and use it in GitHub Desktop.
Disable "illegal reflective access" warnings in JDK 9
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