Reputation: 4427
We are using org.springframework.beans.BeanUtils
(v2.5.x) in our code to copy some properties in our objects.
As a temporary thing, I put a println
in the setter and set a debug point, but I noticed that the copy properties never used the setter. Furthermore, I set a break point on the variable that is being set and it still skips it over.
Whats going on here? How do I break when the variable is being modified?
Upvotes: 1
Views: 362
Reputation: 48741
The second option, in step #5 below, states that you can tell Eclipse to break at the line if the value of the expression changes.
Eclipse: Managing conditional breakpoints
A conditional expression can be applied to a line breakpoint such that the breakpoint suspends execution of a thread in one of these cases:
- when the result of the expression is true
- when the result of the expression changes
A conditional expression can contain arbitrary Java code and may contain more than one statement, allowing breakpoint conditions to implement features like tracing. For example, a condition can execute a print statement and then return a hard coded value to never suspend ("
System.out.println(...); return false;
").
Setting a conditional breakpoint in Eclipse:
To set a condition on a breakpoint:
- Find the breakpoint to which an enabling condition is to be applied (in the Breakpoints View or in the editor marker bar).
- From the breakpoint's pop-up menu, select Breakpoint Properties.... The Breakpoint properties dialog will open.
- In the properties dialog, check the Enable Condition checkbox.
- In the Condition field enter the expression for the breakpoint condition.
- Do one of the following:
- If you want the breakpoint to stop every time the condition evaluates to true, select the condition is 'true' option. The expression provided must be a boolean expression.
- If you want the breakpoint to stop only when the result of the condition changes, select the value of condition changes option.
- Select OK to close the dialog and commit the changes. While the breakpoint is enabled, thread execution suspends before that line of code is executed if the breakpoint condition evaluates to true.
A conditional breakpoint has a question mark overlay on the breakpoint icon.
Upvotes: 1
Reputation: 681
Most Java debuggers have a "Watch" feature to break when an object changes.
If you pull the source with your dependency manager (Gradle or Maven), you can browse into the source and see what BeanUtils is actually doing (probably using Fields).
Upvotes: 0
Reputation: 6093
I believe Spring uses reflection to achieve this, you can read even private fields via the reflection API.
EDIT: of coure this means your getters and setters never get called when using copyProperties.
Upvotes: 1