public static void generateJLObjectStream_hasStaticInitializer ( ClassWriter cw , String classname ) { FieldVisitor fv = cw . visitField ( ACC_PUBLIC + ACC_STATIC , jloObjectStream_hasInitializerMethod , "Ljava/lang/reflect/Method;" , null , null ) ; fv . visitEnd ( ) ; MethodVisitor mv = cw . visitMethod ( ACC_PRIVATE + ACC_STATIC , jloObjectStream_hasInitializerMethod , "(Ljava/lang/Class;)Z" , null , null ) ; mv . visitCode ( ) ; Label l0 = new Label ( ) ; Label l1 = new Label ( ) ; Label l2 = new Label ( ) ; mv . visitTryCatchBlock ( l0 , l1 , l2 , "java/lang/Exception" ) ; mv . visitLabel ( l0 ) ; mv . visitFieldInsn ( GETSTATIC , classname , jloObjectStream_hasInitializerMethod , "Ljava/lang/reflect/Method;" ) ; mv . visitInsn ( ACONST_NULL ) ; mv . visitInsn ( ICONST_1 ) ; mv . visitTypeInsn ( ANEWARRAY , "java/lang/Object" ) ; mv . visitInsn ( DUP ) ; mv . visitInsn ( ICONST_0 ) ; mv . visitVarInsn ( ALOAD , 0 ) ; mv . visitInsn ( AASTORE ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , "java/lang/reflect/Method" , "invoke" , "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;" , false ) ; mv . visitTypeInsn ( CHECKCAST , "java/lang/Boolean" ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , "java/lang/Boolean" , "booleanValue" , "()Z" , false ) ; mv . visitLabel ( l1 ) ; mv . visitInsn ( IRETURN ) ; mv . visitLabel ( l2 ) ; // If not a reloadable type, we'll end up here (the method we called threw IllegalStateException), just make that native method call mv . visitVarInsn ( ASTORE , 1 ) ; mv . visitVarInsn ( ALOAD , 0 ) ; mv . visitMethodInsn ( INVOKESTATIC , classname , "hasStaticInitializer" , "(Ljava/lang/Class;)Z" ) ; mv . visitInsn ( IRETURN ) ; mv . visitMaxs ( 3 , 1 ) ; mv . visitEnd ( ) ; }
Create a method that can be used to intercept the calls to hasStaticInitializer made in the ObjectStreamClass . The method will ask SpringLoaded whether the type has a static initializer . SpringLoaded will be able to answer if it is a reloadable type . If it is not a reloadable type then springloaded will throw an exception which will be caught here and the regular call to hasStaticInitializer will be made .