### Question:
LocalVariablesSorter extends MethodVisitor { @Override public void visitFrame( final int type, final int numLocal, final Object[] local, final int numStack, final Object[] stack) { if (type != Opcodes.F_NEW) { throw new IllegalArgumentException( "LocalVariablesSorter only accepts expanded frames (see ClassReader.EXPAND_FRAMES)"); } Object[] oldRemappedLocals = new Object[remappedLocalTypes.length]; System.arraycopy(remappedLocalTypes, 0, oldRemappedLocals, 0, oldRemappedLocals.length); updateNewLocals(remappedLocalTypes); int oldVar = 0; for (int i = 0; i < numLocal; ++i) { Object localType = local[i]; if (localType != Opcodes.TOP) { Type varType = OBJECT_TYPE; if (localType == Opcodes.INTEGER) { varType = Type.INT_TYPE; } else if (localType == Opcodes.FLOAT) { varType = Type.FLOAT_TYPE; } else if (localType == Opcodes.LONG) { varType = Type.LONG_TYPE; } else if (localType == Opcodes.DOUBLE) { varType = Type.DOUBLE_TYPE; } else if (localType instanceof String) { varType = Type.getObjectType((String) localType); } setFrameLocal(remap(oldVar, varType), localType); } oldVar += localType == Opcodes.LONG || localType == Opcodes.DOUBLE ? 2 : 1; } oldVar = 0; int newVar = 0; int remappedNumLocal = 0; while (oldVar < remappedLocalTypes.length) { Object localType = remappedLocalTypes[oldVar]; oldVar += localType == Opcodes.LONG || localType == Opcodes.DOUBLE ? 2 : 1; if (localType != null && localType != Opcodes.TOP) { remappedLocalTypes[newVar++] = localType; remappedNumLocal = newVar; } else { remappedLocalTypes[newVar++] = Opcodes.TOP; } } super.visitFrame(type, remappedNumLocal, remappedLocalTypes, numStack, stack); remappedLocalTypes = oldRemappedLocals; } LocalVariablesSorter(
      final int access, final String descriptor, final MethodVisitor methodVisitor); protected  LocalVariablesSorter(
      final int api, final int access, final String descriptor, final MethodVisitor methodVisitor); @Override void visitVarInsn(final int opcode, final int var); @Override void visitIincInsn(final int var, final int increment); @Override void visitMaxs(final int maxStack, final int maxLocals); @Override void visitLocalVariable(
      final String name,
      final String descriptor,
      final String signature,
      final Label start,
      final Label end,
      final int index); @Override AnnotationVisitor visitLocalVariableAnnotation(
      final int typeRef,
      final TypePath typePath,
      final Label[] start,
      final Label[] end,
      final int[] index,
      final String descriptor,
      final boolean visible); @Override void visitFrame(
      final int type,
      final int numLocal,
      final Object[] local,
      final int numStack,
      final Object[] stack); int newLocal(final Type type);  }### Answer:
@Test public void testVisitFrame_emptyFrame() { LocalVariablesSorter localVariablesSorter = new LocalVariablesSorter(Opcodes.ACC_PUBLIC, "()V", new MethodNode()); Executable visitFrame = () -> localVariablesSorter.visitFrame(Opcodes.F_NEW, 0, null, 0, null); assertDoesNotThrow(visitFrame); }
@Test public void testVisitFrame_invalidFrameType() { LocalVariablesSorter localVariablesSorter = new LocalVariablesSorter(Opcodes.ACC_PUBLIC, "()V", new MethodNode()); Executable visitFrame = () -> localVariablesSorter.visitFrame(Opcodes.F_FULL, 0, null, 0, null); Exception exception = assertThrows(IllegalArgumentException.class, visitFrame); assertEquals( "LocalVariablesSorter only accepts expanded frames (see ClassReader.EXPAND_FRAMES)", exception.getMessage()); }