背景
(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.csdn.net/chen051318/article/details/68927464
https://zhuanlan.zhihu.com/p/54755387?from_voters_page=true
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/35962.html