/** * Checks that the given string is a valid unqualified name. * * @param version the class version. * @param name the string to be checked. * @param message the message to use in case of error. */ static void checkUnqualifiedName(final int version, final String name, final String message) { checkIdentifier(version, name, 0, -1, message); }
@Override public void visitTryCatchBlock(final Label start, final Label end, final Label handler, final String type) { checkStartCode(); checkEndCode(); checkLabel(start, false, "start label"); checkLabel(end, false, "end label"); checkLabel(handler, false, "handler label"); checkNonDebugLabel(start); checkNonDebugLabel(end); checkNonDebugLabel(handler); if (labels.get(start) != null || labels.get(end) != null || labels.get(handler) != null) { throw new IllegalStateException( "Try catch blocks must be visited before their labels"); } if (type != null) { checkInternalName(type, "type"); } super.visitTryCatchBlock(start, end, handler, type); handlers.add(start); handlers.add(end); }
private void doVisitMethodInsn(int opcode, final String owner, final String name, final String desc, final boolean itf) { checkStartCode(); checkEndCode(); checkOpcode(opcode, 5); if (opcode != Opcodes.INVOKESPECIAL || !"<init>".equals(name)) { checkMethodIdentifier(version, name, "name"); checkInternalName(owner, "owner"); checkMethodDesc(desc); if (opcode == Opcodes.INVOKEVIRTUAL && itf) { throw new IllegalArgumentException(
@Override public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { checkStartCode(); checkEndCode(); checkOpcode(opcode, 4); checkInternalName(owner, "owner"); checkUnqualifiedName(version, name, "name"); checkDesc(desc, false); super.visitFieldInsn(opcode, owner, name, desc); ++insnCount; }
@Override public void visitFieldInsn( final int opcode, final String owner, final String name, final String descriptor) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkOpcodeMethod(opcode, Method.VISIT_FIELD_INSN); checkInternalName(version, owner, "owner"); checkUnqualifiedName(version, name, "name"); checkDescriptor(version, descriptor, false); super.visitFieldInsn(opcode, owner, name, descriptor); ++insnCount; }
@Override public void visitIincInsn(final int var, final int increment) { checkStartCode(); checkEndCode(); checkUnsignedShort(var, "Invalid variable index"); checkSignedShort(increment, "Invalid increment"); super.visitIincInsn(var, increment); ++insnCount; }
@Override public void visitLineNumber(final int line, final Label start) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkUnsignedShort(line, "Invalid line number"); checkLabel(start, true, START_LABEL); super.visitLineNumber(line, start); }
@Override public void visitLineNumber(final int line, final Label start) { checkStartCode(); checkEndCode(); checkUnsignedShort(line, "Invalid line number"); checkLabel(start, true, "start label"); super.visitLineNumber(line, start); }
@Override public void visitIntInsn(final int opcode, final int operand) { checkStartCode(); checkEndCode(); checkOpcode(opcode, 1); switch (opcode) { case Opcodes.BIPUSH: checkSignedByte(operand, "Invalid operand"); break; case Opcodes.SIPUSH: checkSignedShort(operand, "Invalid operand"); break; // case Constants.NEWARRAY: default: if (operand < Opcodes.T_BOOLEAN || operand > Opcodes.T_LONG) { throw new IllegalArgumentException( "Invalid operand (must be an array type code T_...): " + operand); } } super.visitIntInsn(opcode, operand); ++insnCount; }
throw new IllegalArgumentException("invalid handle tag " + tag); checkInternalName(this.version, handle.getOwner(), "handle owner"); if (tag <= Opcodes.H_PUTSTATIC) { checkDescriptor(this.version, handle.getDesc(), false); } else { checkMethodDescriptor(this.version, handle.getDesc()); checkMethodIdentifier(this.version, handleName, "handle name"); checkMethodIdentifier(this.version, constantDynamic.getName(), "constant dynamic name"); checkDescriptor(this.version, constantDynamic.getDescriptor(), false); checkLdcConstant(constantDynamic.getBootstrapMethod()); int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount(); for (int i = 0; i < bootstrapMethodArgumentCount; ++i) { checkLdcConstant(constantDynamic.getBootstrapMethodArgument(i)); checkConstant(value);
| Opcodes.ACC_DEPRECATED); if (!"<init>".equals(name) && !"<clinit>".equals(name)) { CheckMethodAdapter.checkMethodIdentifier(version, name, "method name"); CheckMethodAdapter.checkMethodDescriptor(version, descriptor); if (signature != null) { checkMethodSignature(signature); CheckMethodAdapter.checkInternalName( version, exceptions[i], "exception name at index " + i); if (checkDataFlow) { checkMethodAdapter = new CheckMethodAdapter( api, access, } else { checkMethodAdapter = new CheckMethodAdapter( api, super.visitMethod(access, name, descriptor, signature, exceptions),
/** * Checks a stack frame value. * * @param value the value to be checked. */ private void checkFrameValue(final Object value) { if (value == Opcodes.TOP || value == Opcodes.INTEGER || value == Opcodes.FLOAT || value == Opcodes.LONG || value == Opcodes.DOUBLE || value == Opcodes.NULL || value == Opcodes.UNINITIALIZED_THIS) { return; } else if (value instanceof String) { checkInternalName(version, (String) value, "Invalid stack frame value"); } else if (value instanceof Label) { referencedLabels.add((Label) value); } else { throw new IllegalArgumentException("Invalid stack frame value: " + value); } }
+ Opcodes.ACC_SYNTHETIC + Opcodes.ACC_DEPRECATED + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE if (!"<init>".equals(name) && !"<clinit>".equals(name)) { CheckMethodAdapter.checkMethodIdentifier(version, name, "method name"); CheckMethodAdapter.checkMethodDesc(desc); if (signature != null) { checkMethodSignature(signature); CheckMethodAdapter.checkInternalName(exceptions[i], "exception name at index " + i); cma = new CheckMethodAdapter(access, name, desc, super.visitMethod( access, name, desc, signature, exceptions), labels); } else { cma = new CheckMethodAdapter(super.visitMethod(access, name, desc, signature, exceptions), labels);
@Override public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { checkStartCode(); checkEndCode(); checkMethodIdentifier(version, name, "name"); checkMethodDesc(desc); if (bsm.getTag() != Opcodes.H_INVOKESTATIC && bsm.getTag() != Opcodes.H_NEWINVOKESPECIAL) { throw new IllegalArgumentException("invalid handle tag " + bsm.getTag()); } for (int i = 0; i < bsmArgs.length; i++) { checkLDCConstant(bsmArgs[i]); } super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs); ++insnCount; }
@Override public void visitTypeInsn(final int opcode, final String type) { checkStartCode(); checkEndCode(); checkOpcode(opcode, 3); checkInternalName(type, "type"); if (opcode == Opcodes.NEW && type.charAt(0) == '[') { throw new IllegalArgumentException( "NEW cannot be used to create arrays: " + type); } super.visitTypeInsn(opcode, type); ++insnCount; }
final String descriptor, final boolean isInterface) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkOpcodeMethod(opcode, Method.VISIT_METHOD_INSN); if (opcode != Opcodes.INVOKESPECIAL || !"<init>".equals(name)) { checkMethodIdentifier(version, name, "name"); checkInternalName(version, owner, "owner"); checkMethodDescriptor(version, descriptor); if (opcode == Opcodes.INVOKEVIRTUAL && isInterface) { throw new IllegalArgumentException("INVOKEVIRTUAL can't be used with interfaces");
@Override public void visitIntInsn(final int opcode, final int operand) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkOpcodeMethod(opcode, Method.VISIT_INT_INSN); switch (opcode) { case Opcodes.BIPUSH: checkSignedByte(operand, "Invalid operand"); break; case Opcodes.SIPUSH: checkSignedShort(operand, "Invalid operand"); break; case Opcodes.NEWARRAY: if (operand < Opcodes.T_BOOLEAN || operand > Opcodes.T_LONG) { throw new IllegalArgumentException( "Invalid operand (must be an array type code T_...): " + operand); } break; default: throw new AssertionError(); } super.visitIntInsn(opcode, operand); ++insnCount; }
@Override public void visitLabel(final Label label) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkLabel(label, false, "label"); if (labelInsnIndices.get(label) != null) { throw new IllegalArgumentException("Already visited label"); } labelInsnIndices.put(label, insnCount); super.visitLabel(label); }
@Override public void visitIincInsn(final int var, final int increment) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkUnsignedShort(var, INVALID_LOCAL_VARIABLE_INDEX); checkSignedShort(increment, "Invalid increment"); super.visitIincInsn(var, increment); ++insnCount; }
@Override public void visitTryCatchBlock( final Label start, final Label end, final Label handler, final String type) { checkVisitCodeCalled(); checkVisitMaxsNotCalled(); checkLabel(start, false, START_LABEL); checkLabel(end, false, END_LABEL); checkLabel(handler, false, "handler label"); if (labelInsnIndices.get(start) != null || labelInsnIndices.get(end) != null || labelInsnIndices.get(handler) != null) { throw new IllegalStateException("Try catch blocks must be visited before their labels"); } if (type != null) { checkInternalName(version, type, "type"); } super.visitTryCatchBlock(start, end, handler, type); handlers.add(start); handlers.add(end); }