I have included source code for the class and method as I have used it  in
WordCount.java already in the email. Here is an other copy.

import java.lang.reflect.Field;
import java.lang.reflect.Method;

final class DisableAccessWarning {
   public static void disableAccessWarnings() {
      try {
         Class unsafeClass = Class.forName("sun.misc.Unsafe");
         Field field = unsafeClass.getDeclaredField("theUnsafe");
         field.setAccessible(true);
         Object unsafe = field.get(null);

         Method putObjectVolatile =
unsafeClass.getDeclaredMethod("putObjectVolatile", Object.class,
long.class, Object.class);
         Method staticFieldOffset =
unsafeClass.getDeclaredMethod("staticFieldOffset", Field.class);

         Class loggerClass =
Class.forName("jdk.internal.module.IllegalAccessLogger");
         Field loggerField = loggerClass.getDeclaredField("logger");
         Long offset = (Long) staticFieldOffset.invoke(unsafe, loggerField);
         putObjectVolatile.invoke(unsafe, loggerClass, offset, null);
      } catch (Exception ignored) {
         //ignore
      }
   }
}




Backbutton.co.uk
¯\_(ツ)_/¯
♡۶Java♡۶RMI ♡۶
Make Use Method {MUM}
makeuse.org
<http://www.backbutton.co.uk>


On Tue, 21 Apr 2020 at 09:04, Chesnay Schepler <[email protected]> wrote:

> I do not know where this function comes from (DisableAccessWarning().
> disableAccessWarnings()), so we can't be sure.
>
> On 21/04/2020 00:27, Zahid Rahman wrote:
>
> Hi,
>
> *I was getting these warnings, I think these are due to certain version of
> Maven libraries which is impacting Java frameworks every where.*
>
> WARNING: An illegal reflective access operation has occurred
> WARNING: Illegal reflective access by
> org.jboss.netty.util.internal.ByteBufferUtil (
> file:/home/kub19/.m2/repository/io/netty/netty/3.10.6.Final/netty-3.10.6.Final.jar)
> to method java.nio.DirectByteBuffer.cleaner()
> WARNING: Please consider reporting this to the maintainers of
> org.jboss.netty.util.internal.ByteBufferUtil
> WARNING: Use --illegal-access=warn to enable warnings of further illegal
> reflective access operations
> WARNING: All illegal access operations will be denied in a future release
>
>
> *I used the following code , Can you see any conflict or unwanted impact
> with any Flink functionality ? *
> * new DisableAccessWarning().disableAccessWarnings();*
>
> /** * Implements the "WordCount" program that computes a simple word 
> occurrence histogram * over text files. * * <p>The input is a plain text file 
> with lines separated by newline characters. * * <p>Usage: <code>WordCount 
> --input &lt;path&gt; --output &lt;path&gt;</code><br> * If no parameters are 
> provided, the program is run with default data from {@link WordCountData}. * 
> * <p>This example shows how to: * <ul> * <li>write a simple Flink program. * 
> <li>use Tuple data types. * <li>write and use user-defined functions. * </ul> 
> * */public class WordCount {
>
>    // 
> *************************************************************************   
> //     PROGRAM   // 
> *************************************************************************   
> public static void main(String[] args) throws Exception {
>
>       // disable illegal access warnings      new  
> DisableAccessWarning().disableAccessWarnings();
>
>
> final class DisableAccessWarning {
>    public static void disableAccessWarnings() {
>       try {
>          Class unsafeClass = Class.forName("sun.misc.Unsafe");         Field 
> field = unsafeClass.getDeclaredField("theUnsafe");         
> field.setAccessible(true);         Object unsafe = field.get(null);         
> Method putObjectVolatile = unsafeClass.getDeclaredMethod("putObjectVolatile", 
> Object.class, long.class, Object.class);         Method staticFieldOffset = 
> unsafeClass.getDeclaredMethod("staticFieldOffset", Field.class);         
> Class loggerClass = Class.forName("jdk.internal.module.IllegalAccessLogger"); 
>         Field loggerField = loggerClass.getDeclaredField("logger");         
> Long offset = (Long) staticFieldOffset.invoke(unsafe, loggerField);         
> putObjectVolatile.invoke(unsafe, loggerClass, offset, null);      } catch 
> (Exception ignored) {
>       }
>    }
> }
>
>
> Backbutton.co.uk
> ¯\_(ツ)_/¯
> ♡۶Java♡۶RMI ♡۶
> Make Use Method {MUM}
> makeuse.org
> <http://www.backbutton.co.uk>
>
>
>

Reply via email to