Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Dec 21, 2024
1 parent 31e77e7 commit 05b1804
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ class ShutdownHookManagerPatcher extends ClassVisitor {
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
if (VOID_METHODS.contains(name)) {
// make void methods noops
return new MethodReplacement(mv, () -> { mv.visitInsn(Opcodes.RETURN); });
} else if (BOOLEAN_METHODS.contains(name)) {
// make boolean methods always return false
return new MethodReplacement(mv, () -> {
mv.visitInsn(Opcodes.ICONST_0);
mv.visitInsn(Opcodes.IRETURN);
});
} else if (name.equals("<clinit>")) {
return new MethodReplacement(mv, () -> {
// just initialize the two statics, don't actually get runtime to add shutdown hook
var timeUnitType = Type.getType(TimeUnit.class);
var executorServiceType = Type.getType(ExecutorService.class);
mv.visitFieldInsn(Opcodes.GETSTATIC, timeUnitType.getInternalName(), "SECONDS", timeUnitType.getDescriptor());
Expand Down

0 comments on commit 05b1804

Please sign in to comment.