File tree Expand file tree Collapse file tree
jacodb-core/src/main/kotlin/org/jacodb/impl/cfg Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ class MethodNodeBuilder(
7878 fun build (): MethodNode {
7979 initializeFrame(method)
8080 buildInstructionList()
81+ insertNopInstructions()
8182 val mn = MethodNode ()
8283 mn.name = method.name
8384 mn.desc = method.description
@@ -790,4 +791,23 @@ class MethodNodeBuilder(
790791 error(" Could not load method constant $value " )
791792 }
792793
794+ // We have to insert NOP instructions in empty basic blocks to handle situations with empty handlers of try/catch
795+ private fun insertNopInstructions () {
796+ val firstLabelIndex = currentInsnList.indexOfFirst { it is LabelNode }
797+ val nodesBetweenLabels = mutableListOf<AbstractInsnNode >()
798+ var i = firstLabelIndex + 1
799+ while (i < currentInsnList.size()) {
800+ when (val curInst = currentInsnList[i]) {
801+ is LabelNode -> {
802+ if (nodesBetweenLabels.all { it is LineNumberNode }) {
803+ currentInsnList.insertBefore(curInst, InsnNode (Opcodes .NOP ))
804+ ++ i
805+ }
806+ nodesBetweenLabels.clear()
807+ }
808+ else -> nodesBetweenLabels.add(curInst)
809+ }
810+ ++ i
811+ }
812+ }
793813}
You can’t perform that action at this time.
0 commit comments