Skip to content

Commit 6f2c152

Browse files
committed
Fix error in FastClassVerifier (AnalyzerException with immediate return of ternary operator with generic return type)
1 parent 59f34f5 commit 6f2c152

File tree

3 files changed

+29
-22
lines changed
  • net.tascalate.javaflow.providers.asm3/src/main/java/org/apache/commons/javaflow/providers/asm3
  • net.tascalate.javaflow.providers.asm4/src/main/java/org/apache/commons/javaflow/providers/asm4
  • net.tascalate.javaflow.providers.asm5/src/main/java/org/apache/commons/javaflow/providers/asm5

3 files changed

+29
-22
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Value copyOperation(final AbstractInsnNode insn, Value value) throws Anal
3232
@Override
3333
public Value unaryOperation(final AbstractInsnNode insn, Value value) throws AnalyzerException {
3434
// Fix error with analyzer for try-with-resources (it sees uninitialized values)
35-
if (insn.getOpcode() == Opcodes.ALOAD && (value instanceof BasicValue && !((BasicValue)value).isReference())) {
35+
if (insn.getOpcode() == Opcodes.ARETURN && (value instanceof BasicValue && !((BasicValue)value).isReference())) {
3636
value = newValue(Type.getType("Lnull;"));
3737
}
3838
return super.unaryOperation(insn, value);
@@ -81,13 +81,9 @@ protected boolean isSubTypeOf(final Value value, final Value expected) {
8181
return type.equals(expectedType);
8282
case Type.ARRAY:
8383
case Type.OBJECT:
84-
if ("Lnull;".equals(type.getDescriptor())) {
85-
return true;
86-
} else {
87-
// We are transforming valid bytecode to (hopefully) valid bytecode
88-
// hence pairs of "value" and "expected" must be compatible
89-
return true;//isAssignableFrom(expectedType, type);
90-
}
84+
// We are transforming valid bytecode to (hopefully) valid bytecode
85+
// hence pairs of "value" and "expected" must be compatible
86+
return true;//isAssignableFrom(expectedType, type);
9187
default:
9288
throw new Error("Internal error");
9389
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public BasicValue copyOperation(final AbstractInsnNode insn, BasicValue value) t
2727
}
2828
return super.copyOperation(insn, value);
2929
}
30+
31+
@Override
32+
public BasicValue unaryOperation(final AbstractInsnNode insn, BasicValue value) throws AnalyzerException {
33+
// Fix error with analyzer for try-with-resources (it sees uninitialized values)
34+
if ((insn.getOpcode() == Opcodes.ARETURN) && !value.isReference()) {
35+
value = newValue(Type.getType("Lnull;"));
36+
}
37+
return super.unaryOperation(insn, value);
38+
}
3039

3140
@Override
3241
public BasicValue newValue(final Type type) {
@@ -67,13 +76,9 @@ protected boolean isSubTypeOf(final BasicValue value, final BasicValue expected)
6776
return type.equals(expectedType);
6877
case Type.ARRAY:
6978
case Type.OBJECT:
70-
if ("Lnull;".equals(type.getDescriptor())) {
71-
return true;
72-
} else {
73-
// We are transforming valid bytecode to (hopefully) valid bytecode
74-
// hence pairs of "value" and "expected" must be compatible
75-
return true;//isAssignableFrom(expectedType, type);
76-
}
79+
// We are transforming valid bytecode to (hopefully) valid bytecode
80+
// hence pairs of "value" and "expected" must be compatible
81+
return true;//isAssignableFrom(expectedType, type);
7782
default:
7883
throw new Error("Internal error");
7984
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public BasicValue copyOperation(final AbstractInsnNode insn, BasicValue value) t
2828
return super.copyOperation(insn, value);
2929
}
3030

31+
@Override
32+
public BasicValue unaryOperation(final AbstractInsnNode insn, BasicValue value) throws AnalyzerException {
33+
// Fix error with analyzer for try-with-resources (it sees uninitialized values)
34+
if ((insn.getOpcode() == Opcodes.ARETURN) && !value.isReference()) {
35+
value = newValue(Type.getType("Lnull;"));
36+
}
37+
return super.unaryOperation(insn, value);
38+
}
39+
40+
3141
@Override
3242
public BasicValue newValue(final Type type) {
3343
if (type == null) {
@@ -67,13 +77,9 @@ protected boolean isSubTypeOf(final BasicValue value, final BasicValue expected)
6777
return type.equals(expectedType);
6878
case Type.ARRAY:
6979
case Type.OBJECT:
70-
if ("Lnull;".equals(type.getDescriptor())) {
71-
return true;
72-
} else {
73-
// We are transforming valid bytecode to (hopefully) valid bytecode
74-
// hence pairs of "value" and "expected" must be compatible
75-
return true;//isAssignableFrom(expectedType, type);
76-
}
80+
// We are transforming valid bytecode to (hopefully) valid bytecode
81+
// hence pairs of "value" and "expected" must be compatible
82+
return true;//isAssignableFrom(expectedType, type);
7783
default:
7884
throw new Error("Internal error");
7985
}

0 commit comments

Comments
 (0)