Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse debug breakpoint stopping only on virtual invocation of specific subclass

Let's say we have an abstract class with method onPoke(..).

abstract class BaseValuePanel{
  void onPoke(int depth){
      //blah, blah, ...
  }
}
  • Classes NumberValuePanel, AttributeValuePanel, CategoryValuePanel extend BaseValuePanel.
  • Among others, class DecimalValuePanel extends NumberValuePanel.
  • Among others, class EstimationValuePanel extends DecimalValuePanel.
  • None of the extension classes overrides onPoke(..) method.

Now, I wish to place a breakpoint on onPoke(..) but only when invoked thro an object of the class EstimationValuePanel.

Because right now, if I placed a breakpoint on onPoke(..), the debugger would stop thousands of instances (because of the extensive descendant classes of BaseValuePanel) and only one of which was due to invocation thro EstimationValuePanel.

What is the sequence of set-up or strategy of breakpoint set-up that I need to employ, in order to allow the debugger to stop only when the method was invoked thro EstimationValuePanel.

What I meant by virtual breakpoint ...:
That is, in Java as opposed to C#, non-private, non-static, (overridable) methods are naturally virtual. Hence, virtual invocation here.

like image 400
Blessed Geek Avatar asked Jan 15 '23 06:01

Blessed Geek


1 Answers

Of course you can override the method in class EstimationValuePanel and set the breakpoint only there.

But you can also use conditional breakpoints: go to the properties of the breakpoint on the method onPoke() (right-click or Ctrl + double-click) and select "Conditional". In the text area below you can enter the following condition:

this instanceof EstimationValuePanel

This means the condition is evaluated everytime the method is entered. So if you experience perfomance issues, you should prefer to override the method in EstimationValuePanel.

like image 118
Martin Nyolt Avatar answered Jan 30 '23 22:01

Martin Nyolt