mirror of
https://github.com/EsotericSoftware/reflectasm.git
synced 2025-03-29 13:30:46 +08:00
Use declaring class to access fields.
This fixes finding the wrong field when a subclass has the same field name as a super class.
This commit is contained in:
parent
ee6bb50ddb
commit
9e27555727
@ -260,7 +260,8 @@ public abstract class FieldAccess {
|
||||
break;
|
||||
}
|
||||
|
||||
mv.visitFieldInsn(PUTFIELD, classNameInternal, field.getName(), fieldType.getDescriptor());
|
||||
mv.visitFieldInsn(PUTFIELD, field.getDeclaringClass().getName().replace('.', '/'), field.getName(),
|
||||
fieldType.getDescriptor());
|
||||
mv.visitInsn(RETURN);
|
||||
}
|
||||
|
||||
@ -293,7 +294,8 @@ public abstract class FieldAccess {
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitTypeInsn(CHECKCAST, classNameInternal);
|
||||
mv.visitFieldInsn(GETFIELD, classNameInternal, field.getName(), Type.getDescriptor(field.getType()));
|
||||
mv.visitFieldInsn(GETFIELD, field.getDeclaringClass().getName().replace('.', '/'), field.getName(),
|
||||
Type.getDescriptor(field.getType()));
|
||||
|
||||
Type fieldType = Type.getType(field.getType());
|
||||
switch (fieldType.getSort()) {
|
||||
@ -358,11 +360,13 @@ public abstract class FieldAccess {
|
||||
|
||||
for (int i = 0, n = labels.length; i < n; i++) {
|
||||
if (!labels[i].equals(labelForInvalidTypes)) {
|
||||
Field field = fields.get(i);
|
||||
mv.visitLabel(labels[i]);
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitTypeInsn(CHECKCAST, classNameInternal);
|
||||
mv.visitFieldInsn(GETFIELD, classNameInternal, fields.get(i).getName(), "Ljava/lang/String;");
|
||||
mv.visitFieldInsn(GETFIELD, field.getDeclaringClass().getName().replace('.', '/'), field.getName(),
|
||||
"Ljava/lang/String;");
|
||||
mv.visitInsn(ARETURN);
|
||||
}
|
||||
}
|
||||
@ -451,12 +455,14 @@ public abstract class FieldAccess {
|
||||
|
||||
for (int i = 0, n = labels.length; i < n; i++) {
|
||||
if (!labels[i].equals(labelForInvalidTypes)) {
|
||||
Field field = fields.get(i);
|
||||
mv.visitLabel(labels[i]);
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitTypeInsn(CHECKCAST, classNameInternal);
|
||||
mv.visitVarInsn(loadValueInstruction, 3);
|
||||
mv.visitFieldInsn(PUTFIELD, classNameInternal, fields.get(i).getName(), typeNameInternal);
|
||||
mv.visitFieldInsn(PUTFIELD, field.getDeclaringClass().getName().replace('.', '/'), field.getName(),
|
||||
typeNameInternal);
|
||||
mv.visitInsn(RETURN);
|
||||
}
|
||||
}
|
||||
@ -546,7 +552,8 @@ public abstract class FieldAccess {
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitTypeInsn(CHECKCAST, classNameInternal);
|
||||
mv.visitFieldInsn(GETFIELD, classNameInternal, field.getName(), typeNameInternal);
|
||||
mv.visitFieldInsn(GETFIELD, field.getDeclaringClass().getName().replace('.', '/'), field.getName(),
|
||||
typeNameInternal);
|
||||
mv.visitInsn(returnValueInstruction);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user