[postgis-devel] [PostGIS] #193: PGgeometry.hashCode() does not satisfy certain requirements that are standard in Java

PostGIS trac at osgeo.org
Thu Jun 4 03:32:15 PDT 2009


#193: PGgeometry.hashCode() does not satisfy certain requirements that are
standard in Java
------------------------+---------------------------------------------------
 Reporter:  danpodeanu  |       Owner:  pramsey
     Type:  defect      |      Status:  new    
 Priority:  medium      |   Milestone:         
Component:  postgis     |     Version:  1.3.X  
 Keywords:              |  
------------------------+---------------------------------------------------
 The org.postgis.PGgeometry class from the PostGIS JDBC extension violates
 certain standard requirements of Java: for any two Java objects o1 and o2,
 it should be the case that o1.equals(o2) implies
 o1.hashCode()==o2.hashCode(). Thus, the following code should print 'true'
 and 'true'; however, it prints 'true' and 'false' with the 1.3.6 version
 of the PostGIS JDBC extension:

 {{{
 PGgeometry g1=new PGgeometry("SRID=4326;POINT(2.15426 41.4033)");
 PGgeometry g2=new PGgeometry("SRID=4326;POINT(2.15426 41.4033)");
 System.out.println(g1.equals(g2));
 System.out.println(g1.hashCode()==g2.hashCode());
 }}}

 The error can be demonstrated with the 1.3.6 version of the PostGIS JDBC
 extension (I am using the postgis_1.3.6.jar file from the official
 distribution of PostGIS 1.3.6). I have also tried using an SVN version of
 the 1.4.0 version of the extension and the error persists.

 The effect of this error is that PGgeometry objects do not work with Java
 collections as expected. For example, if g1 from the above example is
 added to a Java hash-set, the set does not necessarily contain g2, and
 this is counterintuive since g1 and g2 are equal. In this sense,
 PGgeometry behaves differently from, say, java.lang.Integer, and this is
 counterintuitive as well because both classes simply wrap a datatype.

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/193>
PostGIS <http://trac.osgeo.org/postgis/>
PostGIS


More information about the postgis-devel mailing list