Dear contributers of Daniweb,

Currently I'm working on an Android/Java project, where I'm running into a problem with the following code.

    private List<Property> filteredList;
    private List<Property> propertyList;

    public List<Property> getPropertyList() {

        Boolean useFilter = false;
        if (!filter_town.trim().equals("")) useFilter = true;
        if (filter_bedrooms > 0) useFilter = true;

        if (useFilter) {
        setFilteredList();
        return filteredList;
        } else {
            return propertyList;
        }
    }

This is a simplified version of my actual method, but somehow the problem persists: when running the program, the debugger shows "return filteredList;" immediately followed by "return propertyList;". How is it possible that both return statements get executed? Even if I only keep the "return propertyList;" statement, the debugger shows two returns of this statement immediately following each other.

After setting breakpoints throughout the method, it shows the following:

  • The method gets called only one-time (thus, only 1 return is expected)
  • The debugger traverses through the method as expected (line-by-line), however, when it hits the return statement, it is immediately followed by another return statement (without traversing the earlier method statements).

If anyone has any input or insight in how this is possible, I will be very thankful!

It's not possible that two return statements in the same method get executed (except if the first is in a try/catch block and throws a caught exception, in which case it starts executing but doesn't finish).
It sounds like one of those trace messages refers to the method from which this one is called? We need to see more of the code.