Collection<Location> (@NotNull Method method, @NotNull List<Location> locations) { int locationsSize = locations.size(); if (locationsSize < 2) { return locations; } VirtualMachine vm = method.declaringType().virtualMachine(); if (!vm.canGetConstantPool() || !vm.canGetBytecodes()) { return locations; } int lineNumber = locations.get(0).lineNumber(); List<Boolean> mask = new ArrayList<>(locationsSize); visit(method, new MethodVisitor(Opcodes.API_VERSION) { boolean myNewBlock = true; @Override public void visitLineNumber(int line, Label start) { if (lineNumber == line) { mask.add(myNewBlock); myNewBlock = false; } } @Override public void visitInsn(int opcode) { if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) { myNewBlock = true; } } @Override public void visitJumpInsn(int opcode, Label label) { myNewBlock = true; } }, true); if (mask.size() == locationsSize) { locations.sort(Comparator.comparing(Location::codeIndex)); List<Location> res = new ArrayList<>(locationsSize); int pos = 0; for (Location location : locations) { if (mask.get(pos++)) { res.add(location); } } return res; } return locations; }