Skip to content

Commit 772a8d0

Browse files
committed
Fix error with bridge methods - continuable should be applied to specialized method of subclass if bridge method (inherited) is continuable
1 parent 5145f7a commit 772a8d0

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

net.tascalate.javaflow.providers.asm3/src/main/java/org/apache/commons/javaflow/providers/asm3/MaybeContinuableClassVisitor.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,19 @@ public MethodVisitor visitMethod(int access, final String name, final String des
8282
boolean isSynthetic = (access & Opcodes.ACC_SYNTHETIC) != 0 ;
8383
if (isSynthetic) {
8484
boolean isPackagePrivate = (access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0 ;
85-
boolean isAccessor = isPackagePrivate && name.startsWith("access$") && (access & Opcodes.ACC_STATIC) != 0;
86-
boolean isBridge = (access & Opcodes.ACC_BRIDGE) != 0;
85+
final boolean isAccessor = isPackagePrivate && name.startsWith("access$") && (access & Opcodes.ACC_STATIC) != 0;
86+
final boolean isBridge = (access & Opcodes.ACC_BRIDGE) != 0;
8787
if (isAccessor || isBridge) {
8888
return new MethodAdapter(NOP) {
8989
@Override
9090
public void visitMethodInsn(int opcode, String owner, String targetName, String targetDesc) {
9191
if (selfclass.equals(owner)) {
92-
normal2synthetic.put(targetName + targetDesc, name + desc);
92+
if (isAccessor) {
93+
normal2synthetic.put(targetName + targetDesc, name + desc);
94+
} else {
95+
// Reversed for bridge
96+
normal2synthetic.put(name + desc, targetName + targetDesc);
97+
}
9398
}
9499
}
95100
};
@@ -120,13 +125,14 @@ public void visitEnd() {
120125

121126
@Override
122127
public void visitEnd() {
128+
visitInheritanceChain();
129+
checkOuterClass();
130+
// Check after inheritance -- required by bridged methods (specialization of inherited)
123131
for (Map.Entry<String, String> n2s : normal2synthetic.entrySet() ) {
124132
if (continuableMethods.contains(n2s.getKey())) {
125133
continuableMethods.add(n2s.getValue());
126134
}
127-
}
128-
visitInheritanceChain();
129-
checkOuterClass();
135+
}
130136
}
131137

132138
private boolean inheritanceChainVisited = false;

net.tascalate.javaflow.providers.asm4/src/main/java/org/apache/commons/javaflow/providers/asm4/MaybeContinuableClassVisitor.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,19 @@ public MethodVisitor visitMethod(int access, final String name, final String des
8080
boolean isSynthetic = (access & Opcodes.ACC_SYNTHETIC) != 0 ;
8181
if (isSynthetic) {
8282
boolean isPackagePrivate = (access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0 ;
83-
boolean isAccessor = isPackagePrivate && name.startsWith("access$") && (access & Opcodes.ACC_STATIC) != 0;
84-
boolean isBridge = (access & Opcodes.ACC_BRIDGE) != 0;
83+
final boolean isAccessor = isPackagePrivate && name.startsWith("access$") && (access & Opcodes.ACC_STATIC) != 0;
84+
final boolean isBridge = (access & Opcodes.ACC_BRIDGE) != 0;
8585
if (isAccessor || isBridge) {
8686
return new MethodVisitor(Opcodes.ASM4) {
8787
@Override
8888
public void visitMethodInsn(int opcode, String owner, String targetName, String targetDesc) {
8989
if (selfclass.equals(owner)) {
90-
normal2synthetic.put(targetName + targetDesc, name + desc);
90+
if (isAccessor) {
91+
normal2synthetic.put(targetName + targetDesc, name + desc);
92+
} else {
93+
// Reversed for bridge
94+
normal2synthetic.put(name + desc, targetName + targetDesc);
95+
}
9196
}
9297
}
9398
};
@@ -118,13 +123,14 @@ public void visitEnd() {
118123

119124
@Override
120125
public void visitEnd() {
126+
visitInheritanceChain();
127+
checkOuterClass();
128+
// Check after inheritance -- required by bridged methods (specialization of inherited)
121129
for (Map.Entry<String, String> n2s : normal2synthetic.entrySet() ) {
122130
if (continuableMethods.contains(n2s.getKey())) {
123131
continuableMethods.add(n2s.getValue());
124132
}
125-
}
126-
visitInheritanceChain();
127-
checkOuterClass();
133+
}
128134
}
129135

130136
private boolean inheritanceChainVisited = false;

net.tascalate.javaflow.providers.asm5/src/main/java/org/apache/commons/javaflow/providers/asm5/MaybeContinuableClassVisitor.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,18 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
8888
@Override
8989
public void visitMethodInsn(int opcode, String owner, String targetName, String targetDesc, boolean intf) {
9090
if (selfclass.equals(owner)) {
91-
normal2synthetic.put(targetName + targetDesc, name + desc);
91+
if (isAccessor) {
92+
normal2synthetic.put(targetName + targetDesc, name + desc);
93+
} else {
94+
// Reversed for bridge
95+
normal2synthetic.put(name + desc, targetName + targetDesc);
96+
}
9297
}
9398
}
9499

95100
@Override
96101
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
97-
this.visitMethodInsn(opcode, owner, name, desc);
102+
this.visitMethodInsn(opcode, owner, name, desc, false);
98103
}
99104
};
100105
}
@@ -130,13 +135,14 @@ public void visitEnd() {
130135

131136
@Override
132137
public void visitEnd() {
138+
visitInheritanceChain();
139+
checkOuterClass();
140+
// Check after inheritance -- required by bridged methods (specialization of inherited)
133141
for (Map.Entry<String, String> n2s : normal2synthetic.entrySet() ) {
134142
if (continuableMethods.contains(n2s.getKey())) {
135143
continuableMethods.add(n2s.getValue());
136144
}
137145
}
138-
visitInheritanceChain();
139-
checkOuterClass();
140146
// Take desugared lambda bodies in consideration always
141147
// If there is no calls to continuable inside then
142148
// there are will be no run-time penalty anyway

0 commit comments

Comments
 (0)