Stream<Location> (@NotNull Method method, int lineNumber) { assert lineNumber > 0; class Visitor extends MethodVisitor implements MethodBytecodeUtil.InstructionOffsetReader { final SmartList<Integer> returnOffsets = new SmartList<>(); private int bytecodeOffset = -1; private boolean lineMatched; private boolean lastAddedReturnIsLastInstruction; protected Visitor() { super(Opcodes.API_VERSION); } @Override public void readBytecodeInstructionOffset(int offset) { bytecodeOffset = offset; } @Override public void visitLineNumber(int line, Label start) { lineMatched = line == lineNumber; } @Override public void visitInsn(int opcode) { lastAddedReturnIsLastInstruction = false; if (lineMatched && Opcodes.IRETURN <= opcode && opcode <= Opcodes.RETURN) { assert bytecodeOffset >= 0; returnOffsets.add(bytecodeOffset); lastAddedReturnIsLastInstruction = true; } } } Visitor visitor = new Visitor(); MethodBytecodeUtil.visit(method, visitor, true); if (visitor.lastAddedReturnIsLastInstruction && visitor.returnOffsets.size() >= 2) { // Return at the end of the method is likely to be implicitly generated, // it is not the conditional return we were looking for, drop it. visitor.returnOffsets.remove(visitor.returnOffsets.size() - 1); } return visitor.returnOffsets.stream().map(offs -> method.locationOfCodeIndex(offs)); }