The Goal
A couple of times in my life of java programmer I used a trick to put some code ending with “return false;” within Eclipse’s conditional breakpoints just for sake of having that code executed each time JVM goes over the breakpoint, but without the actual suspension of the thread. Or well, suspending would happen anyway, but Eclipse will resume thread automatically after executing the code due to “return false” in the end which would indicate “false” for breakpoint condition value to the Eclipse. As a result program will continue to execute, and no suspending that would require manual resuming (or any interaction) would happen.
The simplest example of the case when one can need that would be logging some variable value of which changes in a loop, and you want to know it’s last value before something happens in the system (say exception occurs). Nothing simpler than just putting a breakpoint to a next line after variable assignment, and setting “System.out.println(theVariable); return false” as a breakpoint condition.
The question that bugged me though was wether I can do it in more controller way. For example from Groovy Shell, which is currently my favourite tool for quickly running several lines of ad-hoc Java code, i.e. for scripting using Java (previously I used BeanShell for that). And it turned out that one can do that fairly easy using JPDA/JDI.
Continue reading →