Do not remove boxing when possibly unsuccessful CHECKCAST is performed
This commit is contained in:
committed by
Alexander Udalov
parent
779e2a096e
commit
270e58cf4e
+19
@@ -100,11 +100,30 @@ class RedundantBoxingInterpreter extends BoxingInterpreter {
|
||||
@NotNull AbstractInsnNode insn, @NotNull BasicValue value
|
||||
) throws AnalyzerException {
|
||||
|
||||
if (insn.getOpcode() == Opcodes.CHECKCAST && value instanceof BoxedBasicValue) {
|
||||
TypeInsnNode typeInsn = (TypeInsnNode) insn;
|
||||
|
||||
if (!isSafeCast((BoxedBasicValue) value, typeInsn.desc)) {
|
||||
markValueAsDirty((BoxedBasicValue) value);
|
||||
}
|
||||
}
|
||||
|
||||
processOperationWithBoxedValue(value, insn);
|
||||
|
||||
return super.unaryOperation(insn, value);
|
||||
}
|
||||
|
||||
private static boolean isSafeCast(@NotNull BoxedBasicValue value, @NotNull String descTo) {
|
||||
try {
|
||||
return Class.forName(Type.getObjectType(descTo).getClassName()).isAssignableFrom(
|
||||
Class.forName(value.getType().getClassName())
|
||||
);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public BasicValue copyOperation(@NotNull AbstractInsnNode insn, @NotNull BasicValue value) throws AnalyzerException {
|
||||
|
||||
Reference in New Issue
Block a user