java - How to execute a void method automatically when a breakpoint is hit? -
i'm using latest intellij idea ultimate 16 eap. have code in library initializes object setters:
x createsomething() { x x = new x(); x.sety(z); return x; // breakpoint on line } i'm looking modify returned value's state debugger: calling x.sety(y). tried conditions, because want happen on every hit of breakpointstopping @ breakpoint , using "evaluate expression" window unfeasible.
it's not possible in of normal object oriented ways (e.g. overriding method), nor possible capture result outside method , modify there because it's deep within many calls.
here tries failed due no support language features in debugger. failed dialog asking "would stop @ breakpoint?". language level fixed @ java 6-7 because i'm developing android.
try 1: call method
problem processing vm event:
breakpoint: 'line 9 inclassname.createsomething()(package)'
error: failed evaluate breakpoint condition 'x.sety(y)'
reason: boolean value expected
also tried variants like: x.sety(y); false;, needs expression.
try 2: call method using lambda
problem processing vm event:
breakpoint: 'line 9 inclassname.createsomething()(package)'
error: failed evaluate breakpoint condition '() -> { x.sety(y); return false; }'
reason: lambdas evaluation not supported
try 3: call method have boolean expression
problem processing vm event:
breakpoint: 'line 9 inclassname.createsomething()(package)'
error: failed evaluate breakpoint condition 'new java.util.concurrent.callable<boolean>() { @override public boolean call() { x.sety(y); return false; } }.call()'
reason: anonymous class evaluation not supported
try 4: call static method (working workaround)
i found workaround want share, i'm still looking better solution if knows one: doesn't require recompiling , restarting.
create method in class:
public class someclass { public static boolean fixx(x x) { x.sety(y); return false; // don't stop on breakpoint } }in breakpoint condition add
full.pkg.someclass.fixx(x)
this works, time want modify condition you'll have restart app. parametrized fixx(x, changeabley) solution that.
make sure disable or remove breakpoint prevent headaches modified behavior when debugging unrelated issues.
steps:
- right click on breakpoint
- a tool popup open, in popup click on "more" link @ bottom window open.
- now check "log evaluated expression" checkbox in window , enter method call in given text box e.g methodname().
- click ok , start debugging.
- when breakpoint hit method called before line's execution.
reference: https://www.jetbrains.com/idea/help/configuring-breakpoints.html
screenshot: screenshot of breakpoint configuration window.
intellij has feature add "watches" can execute void method that's manual, not automatic.
Comments
Post a Comment