My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 96: Filter with null values.
1 person starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  jeff.johnston.mn@gmail.com
Closed:  Aug 2009


 
Reported by extremec...@gmail.com, Apr 3, 2008
If I am filtering on 2 columns (A and B) where A matches its filter
but B is NULL the row still appears, even though B does not match the
filter (I'm presuming that a NULL value shouldn't match any filter
except an empty filter).  I believe this is because the
FilterPredicate code sets the value of the result to true if the
column A filter passes and then short circuits column B because its
value is null.  Perhaps the FilterMatchers should be responsible for
dealing with NULL values.

The evaluate method of FilterPredicate looks like:

1   public boolean evaluate(Object item) {
2       boolean result = false;
3
4        try {
5            for (Filter filter : filterSet.getFilters()) {
6                String property = filter.getProperty();
7                Object value = PropertyUtils.getProperty(item,
property);
8
9               if (value != null) {
10                    FilterMatcher match =
filterMatchers.get(filter);
11                    result = match.evaluate(value,
filter.getValue());
12                }
13
14               // short circuit if does not match
15               if (result == false) {
16                    return false;
17               }

           }
       } catch (Exception e) {
           logger.error("Had problems evaluating the items.", e);
       }

       return result;
   }
May 23, 2008
#1 extremec...@gmail.com
(No comment was entered for this change.)
Labels: -Priority-Medium Priority-High
Oct 25, 2008
Project Member #2 jeff.johnston.mn@gmail.com
After testing this out I am not seeing the behavior.
Status: Invalid
Owner: jeff.johnston.mn
Aug 7, 2009
#3 Joost.Pa...@gmail.com
I have this exact problem.

What happens is that (to continue on the original example) is that the filter on
column A gets evaluated first. And thus variable 'result' is set to 'true'. After
that the filter on column B gets evaluated, because the variable 'value' is 'null' on
this column the result never gets evaluated by the FilterMatcher. So when the check
'result == false' is done the variable 'result' is still 'true' because of the filter
on column A.

If there is only one filter on column B the same item won't be show, because the
variable 'result' is never put on 'true'.

Simple fix would be to add:
} else {
    result = false;
}

 after the check 'if (value != null) {'
Aug 7, 2009
#4 Joost.Pa...@gmail.com
Btw. I'm using version 2.4.2
Aug 8, 2009
Project Member #5 jeff.johnston.mn@gmail.com
Great! I see why I was not getting the error now. When I was testing it out my value
was not null, but, instead, the it was empty.

Your fix makes sense and I have applied it to the trunk. If you would like me to do a
custom build for you let me know at jeff.johnston.mn@gmail.com. It is very easy for
me to do. Otherwise the next release will be out in the next week or so.
Status: Accepted
Aug 8, 2009
Project Member #6 jeff.johnston.mn@gmail.com
(No comment was entered for this change.)
Status: Fixed
Aug 9, 2009
#7 Joost.Pa...@gmail.com
Thx for the offer (and fix), and I'll just wait for the next release ;).

Powered by Google Project Hosting