Skip to content

Commit 71294df

Browse files
committed
Upgrade to ASM 5.1
Issue: SPR-14037
1 parent d124a13 commit 71294df

File tree

3 files changed

+99
-11
lines changed

3 files changed

+99
-11
lines changed

spring-core/src/main/java/org/springframework/asm/ClassReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2497,11 +2497,12 @@ public Object readConst(final int item, final char[] buf) {
24972497
int tag = readByte(index);
24982498
int[] items = this.items;
24992499
int cpIndex = items[readUnsignedShort(index + 1)];
2500+
boolean itf = b[cpIndex - 1] == ClassWriter.IMETH;
25002501
String owner = readClass(cpIndex, buf);
25012502
cpIndex = items[readUnsignedShort(cpIndex + 2)];
25022503
String name = readUTF8(cpIndex, buf);
25032504
String desc = readUTF8(cpIndex + 2, buf);
2504-
return new Handle(tag, owner, name, desc);
2505+
return new Handle(tag, owner, name, desc, itf);
25052506
}
25062507
}
25072508
}

spring-core/src/main/java/org/springframework/asm/ClassWriter.java

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ Item newConstItem(final Object cst) {
10521052
}
10531053
} else if (cst instanceof Handle) {
10541054
Handle h = (Handle) cst;
1055-
return newHandleItem(h.tag, h.owner, h.name, h.desc);
1055+
return newHandleItem(h.tag, h.owner, h.name, h.desc, h.itf);
10561056
} else {
10571057
throw new IllegalArgumentException("value " + cst);
10581058
}
@@ -1187,10 +1187,12 @@ public int newMethodType(final String methodDesc) {
11871187
* the name of the field or method.
11881188
* @param desc
11891189
* the descriptor of the field or method.
1190+
* @param itf
1191+
* true if the owner is an interface.
11901192
* @return a new or an already existing method type reference item.
11911193
*/
11921194
Item newHandleItem(final int tag, final String owner, final String name,
1193-
final String desc) {
1195+
final String desc, final boolean itf) {
11941196
key4.set(HANDLE_BASE + tag, owner, name, desc);
11951197
Item result = get(key4);
11961198
if (result == null) {
@@ -1199,8 +1201,7 @@ Item newHandleItem(final int tag, final String owner, final String name,
11991201
} else {
12001202
put112(HANDLE,
12011203
tag,
1202-
newMethod(owner, name, desc,
1203-
tag == Opcodes.H_INVOKEINTERFACE));
1204+
newMethod(owner, name, desc, itf));
12041205
}
12051206
result = new Item(index++, key4);
12061207
put(result);
@@ -1230,10 +1231,44 @@ Item newHandleItem(final int tag, final String owner, final String name,
12301231
* the descriptor of the field or method.
12311232
* @return the index of a new or already existing method type reference
12321233
* item.
1234+
*
1235+
* @deprecated this method is superseded by
1236+
* {@link #newHandle(int, String, String, String, boolean)}.
12331237
*/
1238+
@Deprecated
12341239
public int newHandle(final int tag, final String owner, final String name,
12351240
final String desc) {
1236-
return newHandleItem(tag, owner, name, desc).index;
1241+
return newHandle(tag, owner, name, desc, tag == Opcodes.H_INVOKEINTERFACE);
1242+
}
1243+
1244+
/**
1245+
* Adds a handle to the constant pool of the class being build. Does nothing
1246+
* if the constant pool already contains a similar item. <i>This method is
1247+
* intended for {@link Attribute} sub classes, and is normally not needed by
1248+
* class generators or adapters.</i>
1249+
*
1250+
* @param tag
1251+
* the kind of this handle. Must be {@link Opcodes#H_GETFIELD},
1252+
* {@link Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD},
1253+
* {@link Opcodes#H_PUTSTATIC}, {@link Opcodes#H_INVOKEVIRTUAL},
1254+
* {@link Opcodes#H_INVOKESTATIC},
1255+
* {@link Opcodes#H_INVOKESPECIAL},
1256+
* {@link Opcodes#H_NEWINVOKESPECIAL} or
1257+
* {@link Opcodes#H_INVOKEINTERFACE}.
1258+
* @param owner
1259+
* the internal name of the field or method owner class.
1260+
* @param name
1261+
* the name of the field or method.
1262+
* @param desc
1263+
* the descriptor of the field or method.
1264+
* @param itf
1265+
* true if the owner is an interface.
1266+
* @return the index of a new or already existing method type reference
1267+
* item.
1268+
*/
1269+
public int newHandle(final int tag, final String owner, final String name,
1270+
final String desc, final boolean itf) {
1271+
return newHandleItem(tag, owner, name, desc, itf).index;
12371272
}
12381273

12391274
/**
@@ -1265,7 +1300,7 @@ Item newInvokeDynamicItem(final String name, final String desc,
12651300

12661301
int hashCode = bsm.hashCode();
12671302
bootstrapMethods.putShort(newHandle(bsm.tag, bsm.owner, bsm.name,
1268-
bsm.desc));
1303+
bsm.desc, bsm.isInterface()));
12691304

12701305
int argsLength = bsmArgs.length;
12711306
bootstrapMethods.putShort(argsLength);

spring-core/src/main/java/org/springframework/asm/Handle.java

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public final class Handle {
6464
*/
6565
final String desc;
6666

67+
68+
/**
69+
* Indicate if the owner is an interface or not.
70+
*/
71+
final boolean itf;
72+
6773
/**
6874
* Constructs a new field or method handle.
6975
*
@@ -84,12 +90,44 @@ public final class Handle {
8490
* @param desc
8591
* the descriptor of the field or method designated by this
8692
* handle.
93+
*
94+
* @deprecated this constructor has been superseded
95+
* by {@link #Handle(int, String, String, String, boolean)}.
8796
*/
97+
@Deprecated
8898
public Handle(int tag, String owner, String name, String desc) {
99+
this(tag, owner, name, desc, tag == Opcodes.H_INVOKEINTERFACE);
100+
}
101+
102+
/**
103+
* Constructs a new field or method handle.
104+
*
105+
* @param tag
106+
* the kind of field or method designated by this Handle. Must be
107+
* {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
108+
* {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
109+
* {@link Opcodes#H_INVOKEVIRTUAL},
110+
* {@link Opcodes#H_INVOKESTATIC},
111+
* {@link Opcodes#H_INVOKESPECIAL},
112+
* {@link Opcodes#H_NEWINVOKESPECIAL} or
113+
* {@link Opcodes#H_INVOKEINTERFACE}.
114+
* @param owner
115+
* the internal name of the class that owns the field or method
116+
* designated by this handle.
117+
* @param name
118+
* the name of the field or method designated by this handle.
119+
* @param desc
120+
* the descriptor of the field or method designated by this
121+
* handle.
122+
* @param itf
123+
* true if the owner is an interface.
124+
*/
125+
public Handle(int tag, String owner, String name, String desc, boolean itf) {
89126
this.tag = tag;
90127
this.owner = owner;
91128
this.name = name;
92129
this.desc = desc;
130+
this.itf = itf;
93131
}
94132

95133
/**
@@ -135,6 +173,17 @@ public String getDesc() {
135173
return desc;
136174
}
137175

176+
/**
177+
* Returns true if the owner of the field or method designated
178+
* by this handle is an interface.
179+
*
180+
* @return true if the owner of the field or method designated
181+
* by this handle is an interface.
182+
*/
183+
public boolean isInterface() {
184+
return itf;
185+
}
186+
138187
@Override
139188
public boolean equals(Object obj) {
140189
if (obj == this) {
@@ -144,27 +193,30 @@ public boolean equals(Object obj) {
144193
return false;
145194
}
146195
Handle h = (Handle) obj;
147-
return tag == h.tag && owner.equals(h.owner) && name.equals(h.name)
148-
&& desc.equals(h.desc);
196+
return tag == h.tag && itf == h.itf && owner.equals(h.owner)
197+
&& name.equals(h.name) && desc.equals(h.desc);
149198
}
150199

151200
@Override
152201
public int hashCode() {
153-
return tag + owner.hashCode() * name.hashCode() * desc.hashCode();
202+
return tag + (itf? 64: 0) + owner.hashCode() * name.hashCode() * desc.hashCode();
154203
}
155204

156205
/**
157206
* Returns the textual representation of this handle. The textual
158207
* representation is:
159208
*
160209
* <pre>
210+
* for a reference to a class:
161211
* owner '.' name desc ' ' '(' tag ')'
212+
* for a reference to an interface:
213+
* owner '.' name desc ' ' '(' tag ' ' itf ')'
162214
* </pre>
163215
*
164216
* . As this format is unambiguous, it can be parsed if necessary.
165217
*/
166218
@Override
167219
public String toString() {
168-
return owner + '.' + name + desc + " (" + tag + ')';
220+
return owner + '.' + name + desc + " (" + tag + (itf? " itf": "") + ')';
169221
}
170222
}

0 commit comments

Comments
 (0)