Error in org.geotools.filter.BetweenFilterImpl (SLD)
----------------------------------------------------

         Key: GEOT-764
         URL: http://jira.codehaus.org/browse/GEOT-764
     Project: GeoTools
        Type: Bug
  Components: styling  
    Versions: 2.1.0    
 Environment: Windows XP
Java JDK 1.5_01
    Reporter: Ed Mackenzie
    Priority: Minor


The BetweenFilterImpl class causes exceptions when processing numeric 
attributes during it's compare method operation.

The following snippet from an SLD file exhibits the problem when processed.

...
<ogc:Filter>
 <ogc:PropertyIsBetween>                        
 <ogc:PropertyName>Ccode</ogc:PropertyName>     
 <ogc:LowerBoundary><ogc:Literal>40</ogc:Literal></ogc:LowerBoundary>
 <ogc:UpperBoundary><ogc:Literal>50</ogc:Literal></ogc:UpperBoundary>
 </ogc:PropertyIsBetween>
</ogc:Filter> 
...

The Ccode property is a value between 1 and 100. During operation the compare 
method throws an IllegalArgumentException and execution of the code is halted.

The problem is caused by the improper conversion of attribute data from a 
String value to a numeric one in the compare method of the failing class. A 
suggested fix is posted below:

... Line 98 of BetweenFilterImpl.java
if (leftObj instanceof Number &&
 //middleObj instanceof Number && //problem condition
 rightObj instanceof Number) { //handle for NumberFormatException
 try {
  double mid = Double.parseDouble((String)middleObj);
  double left = ((Number)leftObj).doubleValue();
  double right = ((Number)rightObj).doubleValue();
  //double mid = ((Number)middleObj).doubleValue();
  return (left <= mid) && (right >= mid);
 } catch (NumberFormatException e) {
  System.out.println("Cannot handle character attribute!");
  //e.printStackTrace();
  return false;
}
...

This version fixes the problem and the SLD is correctly processed. If both left 
and right values are numeric, the middle value can be treated as numeric - at 
least until the exception is caught and false is returned.
 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to