Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a breakpoint in a setter method in IntelliJ IDEA that is generated with Lombok?

Tags:

Is there a way in IntelliJ IDEA to set a breakpoint in a setter method that is generated by Lombok?

This would be very useful in certain debugging scenarios, e.g. to see when the setter is called from a framework like Hibernate.

In fact, the generated setter methods are displayed in the structure view of IntelliJ IDEA (Lombok plugin in use). But I've not found a way to set a breakpoint via the context menu or such.

like image 281
rmoestl Avatar asked Jul 15 '14 07:07

rmoestl


People also ask

How do I set a break point in IntelliJ?

Manage breakpoints To do this, go to Settings/Preferences | Build, Execution, Deployment | Debugger and select Drag to the editor or click with middle mouse button. Clicking a breakpoint will then enable or disable it.

How do you create a breakpoint in a method?

Press F3 and then press F9 to add a breakpoint. This adds a breakpoint to the first method found using the trick.

How do I Debug a method in IntelliJ?

Run the program in debug modeClick the Run icon in the gutter, then select Modify Run Configuration. Enter arguments in the Program arguments field. Click the Run button near the main method. From the menu, select Debug.


1 Answers

As a workaround you may use Java Field Watchpoint. In such a case every access/modification of the field will result in a break point.

The disadvantage of this approach is getting a thread suspension both when you access/modify the field directly or using getter/setter methods.

However, when you catch a breakpoint using setter methods, IDEA also shows a parameter (with the same name as the field used for the watch point) in Variables window and the breakpoint is shown not in the field's line, but in the class' line.

Setter Break point

The following short description, how to create a field watch point, was copied from https://www.jetbrains.com/idea/help/creating-field-watchpoints.html:

  1. On the main menu, choose Run | View Breakpoints, or press Ctrl+Shift+F8.
  2. In the Breakpoints dialog box that opens, click add (plus icon) button.
  3. Select Field Watchpoint from the drop-down list: "Java Field Watchpoints"
  4. In the Add Field Watchpoint dialog box that opens, specify the following:
    Fully qualified name of a class that contains the desired field. You can type it manually, or click browse Button, and find the desired class by name, or from the project.
    Field name. You can type it manually, or click browse Button and select the desired field from the list of fields in the selected class.
  5. Also, you may set other options like Field access (for getters) or Field modification (for setters)
like image 127
Фима Гирин Avatar answered Oct 23 '22 16:10

Фима Гирин