jdk1.8中使用aspectjweaver报错 Invalid byte tag in constant pool 18

背景

(1)jdk 1.8

(2)aspectjweaver 1.6.10

<dependency>
	<groupId>org.aspectj</groupId>
	<artifactId>aspectjweaver</artifactId>
	<version>1.6.10</version>
</dependency>

(3)在方法中使用jdk1.8新特性lambda表达式后,执行方法报错,报错如下:

org.aspectj.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 18
at org.aspectj.apache.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:192)
at org.aspectj.apache.bcel.classfile.ClassParser.parse(ClassParser.java:131)

分析

查看源码发现 1.6.10版本的aspectjweaver,读取class文件中的常量池出错,

不支持读取class文件常量池中的数据项:CONSTANT_InvokeDynamic_info(类型标志:18)

 static final Constant readConstant(DataInputStream dis) throws IOException, ClassFormatException {
        byte b = dis.readByte();
        switch(b) {
        case 1:
            return new ConstantUtf8(dis);
        case 2:
        default:
            throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
        case 3:
            return new ConstantInteger(dis);
        case 4:
            return new ConstantFloat(dis);
        case 5:
            return new ConstantLong(dis);
        case 6:
            return new ConstantDouble(dis);
        case 7:
            return new ConstantClass(dis);
        case 8:
            return new ConstantString(dis);
        case 9:
            return new ConstantFieldref(dis);
        case 10:
            return new ConstantMethodref(dis);
        case 11:
            return new ConstantInterfaceMethodref(dis);
        case 12:
            return new ConstantNameAndType(dis);
        }
    }

解决办法

升级aspectjweaver,使其支持读取新的数据项:CONSTANT_InvokeDynamic_info(类型标志:18)。比如升级到 1.8.9

<dependency>
	<groupId>org.aspectj</groupId>
	<artifactId>aspectjweaver</artifactId>
	<version>1.8.9</version>
</dependency>
public abstract class Constant implements Cloneable, Node {
    protected byte tag;

    Constant(byte tag) {
        this.tag = tag;
    }

    public final byte getTag() {
        return this.tag;
    }

    public String toString() {
        return Constants.CONSTANT_NAMES[this.tag] + "[" + this.tag + "]";
    }

    public abstract void accept(ClassVisitor var1);

    public abstract void dump(DataOutputStream var1) throws IOException;

    public abstract Object getValue();

    public Constant copy() {
        try {
            return (Constant)super.clone();
        } catch (CloneNotSupportedException var2) {
            return null;
        }
    }

    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    static final Constant readConstant(DataInputStream dis) throws IOException, ClassFormatException {
        byte b = dis.readByte();
        switch(b) {
        case 1:
            return new ConstantUtf8(dis);
        case 2:
        case 13:
        case 14:
        case 17:
        default:
            throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
        case 3:
            return new ConstantInteger(dis);
        case 4:
            return new ConstantFloat(dis);
        case 5:
            return new ConstantLong(dis);
        case 6:
            return new ConstantDouble(dis);
        case 7:
            return new ConstantClass(dis);
        case 8:
            return new ConstantString(dis);
        case 9:
            return new ConstantFieldref(dis);
        case 10:
            return new ConstantMethodref(dis);
        case 11:
            return new ConstantInterfaceMethodref(dis);
        case 12:
            return new ConstantNameAndType(dis);
        case 15:
            return new ConstantMethodHandle(dis);
        case 16:
            return new ConstantMethodType(dis);
        case 18:
            return new ConstantInvokeDynamic(dis);
        }
    }

参考文献

https://blog.youkuaiyun.com/chen051318/article/details/68927464

https://zhuanlan.zhihu.com/p/54755387?from_voters_page=true

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值