Java Magazine, July/August 2018
ORACLE COM JAVAMAGAZINE JULY AUGUST 2018 51 libraries In the previous code I call in readAllBytes directly rather than passing in to the ClassReader constructor This is because the ASM class ClassReader consumes input streams so I cant reuse in after its been used to create a class reader Next I create an instance of our custom class visitor PureJavaCheckingClassVisitor This visitor simply visits the metadata for each method in the class being considered and records whether any method is native It is defined as the following public class PureJavaCheckingClassVisitor extends ClassVisitor private boolean containsNative false public PureJavaCheckingClassVisitor super Opcodes ASM5 @ Override public MethodVisitor visitMethod int flags String name String desc String signature String exceptions if flags ACC_ NATIVE 0 containsNative true return new MethodVisitor Opcodes ASM5 public boolean containsNative return containsNative If the class visitor ever sees a native method it sets a flag The flag is read by the PureJava ClassLoader which rejects the class with a ClassNotFoundException if the flag has been set This
You must have JavaScript enabled to view digital editions.