Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug lombok objects

Does anyone know how to set a breakpoint in the following Person.toString() when using Eclipse or IntelliJ IDEA?

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

@ToString
@AllArgsConstructor
@Data
public class Person {
    private String lastName;
    private String firstName;
}

EDIT:

If possible, I want to stop only when toString() is called.

like image 572
Kohei TAMURA Avatar asked Jul 27 '17 06:07

Kohei TAMURA


People also ask

What is Lombok?

What is Lombok. Project Lombok (from now on, Lombok) is an annotation-based Java library that allows you to reduce boilerplate code. Lombok offers various annotations aimed at replacing Java code that is well known for being boilerplate, repetitive, or tedious to write.


1 Answers

You're asking about both Eclipse and IntelliJ IDEA, and the answers are very different:

  • In Eclipse, right click on the method in the Members view and use "Toggle method breakpoint".
  • In IDEA, there is no solution, but there are good workarounds (see below) and there's a solution described in the comment by @PeterVerhas.

Umm, If possible, I don't want to change source code.

You're surely using version control, so nothing can go wrong, right? If not, then please start using it ASAP as I can't imagine any work without it.

The workaround is very easy despite having several steps:

  1. First, use version control to make sure you don't lose the current state (I usually just move everything down using "Rescan" and "Stage Changed" in git-gui).
  2. Do "Refactor" -> "Delombok" -> "@ToString" (IDEA only) and any other changes you want for debugging.
  3. Debug.
  4. Undo the changes in editor (if possible).
  5. Last, use version control to view the state of the working tree ("Rescan" in git-gui) and possibly to revert the unwanted changes ("Commit" -> "Revert changes" in git-gui) and/or to verify the state of the working tree.

Apart from debugging, which usually takes rather long, each of the steps takes one or two seconds. So there's hardly any overhead. Trust me, I do temporary code changes a few times a day.

like image 61
maaartinus Avatar answered Sep 22 '22 10:09

maaartinus