Upgrade to ASM 5.1
Issue: SPR-14037
This commit is contained in:
@@ -2497,11 +2497,12 @@ public class ClassReader {
|
||||
int tag = readByte(index);
|
||||
int[] items = this.items;
|
||||
int cpIndex = items[readUnsignedShort(index + 1)];
|
||||
boolean itf = b[cpIndex - 1] == ClassWriter.IMETH;
|
||||
String owner = readClass(cpIndex, buf);
|
||||
cpIndex = items[readUnsignedShort(cpIndex + 2)];
|
||||
String name = readUTF8(cpIndex, buf);
|
||||
String desc = readUTF8(cpIndex + 2, buf);
|
||||
return new Handle(tag, owner, name, desc);
|
||||
return new Handle(tag, owner, name, desc, itf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1052,7 +1052,7 @@ public class ClassWriter extends ClassVisitor {
|
||||
}
|
||||
} else if (cst instanceof Handle) {
|
||||
Handle h = (Handle) cst;
|
||||
return newHandleItem(h.tag, h.owner, h.name, h.desc);
|
||||
return newHandleItem(h.tag, h.owner, h.name, h.desc, h.itf);
|
||||
} else {
|
||||
throw new IllegalArgumentException("value " + cst);
|
||||
}
|
||||
@@ -1187,10 +1187,12 @@ public class ClassWriter extends ClassVisitor {
|
||||
* the name of the field or method.
|
||||
* @param desc
|
||||
* the descriptor of the field or method.
|
||||
* @param itf
|
||||
* true if the owner is an interface.
|
||||
* @return a new or an already existing method type reference item.
|
||||
*/
|
||||
Item newHandleItem(final int tag, final String owner, final String name,
|
||||
final String desc) {
|
||||
final String desc, final boolean itf) {
|
||||
key4.set(HANDLE_BASE + tag, owner, name, desc);
|
||||
Item result = get(key4);
|
||||
if (result == null) {
|
||||
@@ -1199,8 +1201,7 @@ public class ClassWriter extends ClassVisitor {
|
||||
} else {
|
||||
put112(HANDLE,
|
||||
tag,
|
||||
newMethod(owner, name, desc,
|
||||
tag == Opcodes.H_INVOKEINTERFACE));
|
||||
newMethod(owner, name, desc, itf));
|
||||
}
|
||||
result = new Item(index++, key4);
|
||||
put(result);
|
||||
@@ -1230,10 +1231,44 @@ public class ClassWriter extends ClassVisitor {
|
||||
* the descriptor of the field or method.
|
||||
* @return the index of a new or already existing method type reference
|
||||
* item.
|
||||
*
|
||||
* @deprecated this method is superseded by
|
||||
* {@link #newHandle(int, String, String, String, boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public int newHandle(final int tag, final String owner, final String name,
|
||||
final String desc) {
|
||||
return newHandleItem(tag, owner, name, desc).index;
|
||||
return newHandle(tag, owner, name, desc, tag == Opcodes.H_INVOKEINTERFACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a handle to the constant pool of the class being build. Does nothing
|
||||
* if the constant pool already contains a similar item. <i>This method is
|
||||
* intended for {@link Attribute} sub classes, and is normally not needed by
|
||||
* class generators or adapters.</i>
|
||||
*
|
||||
* @param tag
|
||||
* the kind of this handle. Must be {@link Opcodes#H_GETFIELD},
|
||||
* {@link Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD},
|
||||
* {@link Opcodes#H_PUTSTATIC}, {@link Opcodes#H_INVOKEVIRTUAL},
|
||||
* {@link Opcodes#H_INVOKESTATIC},
|
||||
* {@link Opcodes#H_INVOKESPECIAL},
|
||||
* {@link Opcodes#H_NEWINVOKESPECIAL} or
|
||||
* {@link Opcodes#H_INVOKEINTERFACE}.
|
||||
* @param owner
|
||||
* the internal name of the field or method owner class.
|
||||
* @param name
|
||||
* the name of the field or method.
|
||||
* @param desc
|
||||
* the descriptor of the field or method.
|
||||
* @param itf
|
||||
* true if the owner is an interface.
|
||||
* @return the index of a new or already existing method type reference
|
||||
* item.
|
||||
*/
|
||||
public int newHandle(final int tag, final String owner, final String name,
|
||||
final String desc, final boolean itf) {
|
||||
return newHandleItem(tag, owner, name, desc, itf).index;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1265,7 +1300,7 @@ public class ClassWriter extends ClassVisitor {
|
||||
|
||||
int hashCode = bsm.hashCode();
|
||||
bootstrapMethods.putShort(newHandle(bsm.tag, bsm.owner, bsm.name,
|
||||
bsm.desc));
|
||||
bsm.desc, bsm.isInterface()));
|
||||
|
||||
int argsLength = bsmArgs.length;
|
||||
bootstrapMethods.putShort(argsLength);
|
||||
|
||||
@@ -64,6 +64,12 @@ public final class Handle {
|
||||
*/
|
||||
final String desc;
|
||||
|
||||
|
||||
/**
|
||||
* Indicate if the owner is an interface or not.
|
||||
*/
|
||||
final boolean itf;
|
||||
|
||||
/**
|
||||
* Constructs a new field or method handle.
|
||||
*
|
||||
@@ -84,12 +90,44 @@ public final class Handle {
|
||||
* @param desc
|
||||
* the descriptor of the field or method designated by this
|
||||
* handle.
|
||||
*
|
||||
* @deprecated this constructor has been superseded
|
||||
* by {@link #Handle(int, String, String, String, boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public Handle(int tag, String owner, String name, String desc) {
|
||||
this(tag, owner, name, desc, tag == Opcodes.H_INVOKEINTERFACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new field or method handle.
|
||||
*
|
||||
* @param tag
|
||||
* the kind of field or method designated by this Handle. Must be
|
||||
* {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
|
||||
* {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
|
||||
* {@link Opcodes#H_INVOKEVIRTUAL},
|
||||
* {@link Opcodes#H_INVOKESTATIC},
|
||||
* {@link Opcodes#H_INVOKESPECIAL},
|
||||
* {@link Opcodes#H_NEWINVOKESPECIAL} or
|
||||
* {@link Opcodes#H_INVOKEINTERFACE}.
|
||||
* @param owner
|
||||
* the internal name of the class that owns the field or method
|
||||
* designated by this handle.
|
||||
* @param name
|
||||
* the name of the field or method designated by this handle.
|
||||
* @param desc
|
||||
* the descriptor of the field or method designated by this
|
||||
* handle.
|
||||
* @param itf
|
||||
* true if the owner is an interface.
|
||||
*/
|
||||
public Handle(int tag, String owner, String name, String desc, boolean itf) {
|
||||
this.tag = tag;
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.itf = itf;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,6 +173,17 @@ public final class Handle {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the owner of the field or method designated
|
||||
* by this handle is an interface.
|
||||
*
|
||||
* @return true if the owner of the field or method designated
|
||||
* by this handle is an interface.
|
||||
*/
|
||||
public boolean isInterface() {
|
||||
return itf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
@@ -144,13 +193,13 @@ public final class Handle {
|
||||
return false;
|
||||
}
|
||||
Handle h = (Handle) obj;
|
||||
return tag == h.tag && owner.equals(h.owner) && name.equals(h.name)
|
||||
&& desc.equals(h.desc);
|
||||
return tag == h.tag && itf == h.itf && owner.equals(h.owner)
|
||||
&& name.equals(h.name) && desc.equals(h.desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return tag + owner.hashCode() * name.hashCode() * desc.hashCode();
|
||||
return tag + (itf? 64: 0) + owner.hashCode() * name.hashCode() * desc.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,13 +207,16 @@ public final class Handle {
|
||||
* representation is:
|
||||
*
|
||||
* <pre>
|
||||
* for a reference to a class:
|
||||
* owner '.' name desc ' ' '(' tag ')'
|
||||
* for a reference to an interface:
|
||||
* owner '.' name desc ' ' '(' tag ' ' itf ')'
|
||||
* </pre>
|
||||
*
|
||||
* . As this format is unambiguous, it can be parsed if necessary.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return owner + '.' + name + desc + " (" + tag + ')';
|
||||
return owner + '.' + name + desc + " (" + tag + (itf? " itf": "") + ')';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user