Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using IntelliJ debugger, is it possible to continue through a collection iteration until a variable returns null?

The following code snippet is part of a Spring MVC controller. Using commons-collections, it iterates over a List of County objects and transforms it into a List of String[] to return to the client. Using the value from the "searchTerm" variable to find the data. The problem I'm having is every so often, a particular search term causes the transformer to throw an exception because the County .getState() method seems to return null. So I'm wondering if using IntelliJ's debugger, can I tell it to continually iterate until a variable is null. A breakpoint causes me to step over each iteration manually, but with a large collection, that could take a while.

Thanks.

public List<String[]> cityLookup(@PathVariable String searchTerm) {
    List<County> counties = countyService.findAllByPartialCity(searchTerm);

    return new ArrayList<String[]>(CollectionUtils.collect(counties, new Transformer() {
        @Override
        public Object transform(Object o) {
            return new String[]{((County) o).getId().getCity(), ((County) o).getState().getStateCode()};
        }
    }));
}
like image 332
Patrick Grimard Avatar asked Jan 28 '26 19:01

Patrick Grimard


2 Answers

In the breakpoints dialog there should be a conditions option.

http://jetbrains.dzone.com/tips/set-conditional-breakpoints-id

like image 103
Kevin Bowersox Avatar answered Jan 30 '26 09:01

Kevin Bowersox


No, you can't do what you're suggesting.

I would recommend that you break that return line into two: one to fetch the values and another to construct the array to be returned.

You can put the breakpoint at the return line and inspect the values before you construct it.

like image 31
duffymo Avatar answered Jan 30 '26 09:01

duffymo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!