Skip over certain classes when using Step Into in Eclipse’s debugger

Whenever I use the Step Into feature (F5) in Eclipse’s debugger, I’m mainly interested in stepping through code in my own classes, not the ones from external libraries or even Java classes.

For example, there’s almost no reason to ever want to step into Spring’s code or proxy classes (other than to learn more about them or maybe debug a potential bug in Spring). And normally I’m not interested in Java util classes (eg. ArrayList). This also goes for Hibernate, Apache Commons, Google and many other external libraries.

Fortunately, Eclipse makes it easy to specify which classes to skip by allowing step filters. This makes it easier to focus on your own code and also keeps your editor area clean since Eclipse won’t be opening classes in separate editors all the time.

Enable Step Filters

To use step filters, the first step is to enable it. Eclipse comes with some default filters so let’s start by enabling them all. This will filter all Java classes (ie. java.*) and all Sun classes (ie. sun.*).

  1. Go to Window > Preferences > Java > Debug > Step Filtering.
  2. Select the option Use Step Filters.
  3. Click Select All to enable all the filters.
  4. Leave the other options below the filter list as-is.

Here’s an example of what it should look like:

NB: Even with step filters enabled, you can still set breakpoints within any of these classes (if you have the source) and Eclipse will still stop at the breakpoint. Step filtering only affects the way that Step Into works.

Also note that Eclipse will still step into your classes if they’re called from the ignored classes. For example, when you call Collections.sort(List, Comparator) and pass your own Comparator implementation, Eclipse will not step into the sort code, but it will step into your Comparator when it’s called by the sort code.

If you want to change this behaviour (ie. prevent Eclipse from stopping in your method), then deselect Step through filters. However, I’d recommend only doing this if you’ve tried out the default, because most times you’ll probably want to step through your own code.

The next step is to create some step filters of your own.

Creating your own step filters

Once you’ve enabled step filters, all you have to do is add the classes you want to filter. Let’s assume that we want to ignore all classes from Spring, especially proxy classes.

  1. If you’re not there already, go to Window > Preferences > Java > Debug > Step Filtering.
  2. Click Add Filter… A dialog should appear prompting you to enter a pattern.
  3. Enter a regular expression for the classes you want to filter in the Pattern to filter field then click Ok. In our example, enter org.springframework.* (see image below). It’s easier to specify the top level package name with an asterix at the end.
  4. Add another filter with the pattern $Proxy* to skip over Spring proxy classes (eg. when using Spring Transactions).
  5. Click Ok on the Preferences dialog when you’re done.

Here’s what the step filter pattern dialog should look like:

Now when you use the debugger, you won’t be taken into Spring classes when you use Step Into (F5).

Some ideas for custom filters

In addition to the Spring classes, you might also want to consider adding the following common libraries to your step filters to make debugging easier:

  • org.apache.*
  • org.hibernate.*
  • com.google.*
  • org.eclipse.*
  • org.osgi.*

The last two are especially useful if you’re doing Eclipse RCP and/or OSGi development.

Related Tips

Support Eclipse On E

8 thoughts on “Skip over certain classes when using Step Into in Eclipse’s debugger

  1. much better than adding filters manually in the prefs imho:
    Add them automatically by right-click the appropriate thread in the Debug window and choose “Filter Type” or “Filter Package”

    • Thanks vet, great tip. It’s a shame it only allows you to filter the class’s package but not any of the parent packages. So you can filter org.eclipse.swt.custom.* but not org.eclipse.swt.* or org.eclipse.*.

      A handy tip nonetheless.

  2. and what, if i have 50 dependencies i have to add them all. that is ridiculous. It should be standard behaviour that IT DOES NOT step in to code modules that you don’t have the source for. that really should be a no brainer.

    • Pleasure, thanks for the compliment. Unfortunately there isn’t a “only debug these packages” flag but the Step Filtering Help does mention that you can enter a regular expression in the filter.

      So, if your company’s package names are com.mypackage, then you could try entering a filter of ^[a-b,d-z].* to ignore all packages not starting with a “c” and another filter of ^com.[a-l,n-z] to ignore all packages not starting with “com.m”. It’s not perfect, but at least you’ll eliminate 99% of any additional dependencies you add.

      I haven’t tried it myself so I can’t guarantee that it works but Eclipse claiming it’s a regex should mean that it should work. Let me know if it works.

Leave a Reply

Your email address will not be published. Required fields are marked *