fix: resolve NPE in enum processing

This commit is contained in:
Skylot
2021-06-04 20:21:38 +01:00
parent 0541748e5f
commit 592eef3cda
@@ -192,12 +192,13 @@ public class EnumVisitor extends AbstractVisitor {
if (ctrMth != null) {
markArgsForSkip(ctrMth);
}
if (co.getResult().getSVar().getUseList().size() <= 2) {
RegisterArg coResArg = co.getResult();
if (coResArg == null || coResArg.getSVar().getUseList().size() <= 2) {
InsnRemover.removeWithoutUnbind(classInitMth, staticBlock, co);
} else {
// constructor result used in other places -> replace constructor with enum field get (SGET)
IndexInsnNode enumGet = new IndexInsnNode(InsnType.SGET, enumField.getField().getFieldInfo(), 0);
enumGet.setResult(co.getResult().duplicate());
enumGet.setResult(coResArg.duplicate());
BlockUtils.replaceInsn(classInitMth, staticBlock, co, enumGet);
}
}