jdev 10.1.3.2 oracle.jbo.domain.Date problem (BUG???)
456775Mar 1 2007 — edited Mar 13 2007I have found problem regarding oracle.jbo.domain.Date class which I think should be treated as bug. Comparing java.util.Date object with object returned by getValue() method of oracle.jbo.domain.Date is not commute. Suppose we have one object java.util.Date A and second oracle.jbo.domain.Date B object. If both are set to the same date value than both A.equals(B.getValue()) and B.getValue().equals(A) should give true but it is not the case. Second expression gives false. The reason of this is that the equals() method in the second expression is not from java.util.Date but from java.sql.Timestamp. java.sql.Timestamp is class of result from oracle.jbo.domain.Date.getValue() if date has time different than 00:00:00. Code of method oracle.jbo.domain.Date.getValue() should not use casting to java.util.Date but should return new java.util.Date object to ensure commutable comparison. Even worse situation is if one tries to use comparTo() metod of java.util.Date because it gives class cast exception.
Below small example to test the case
oracle.jbo.domain.Date oraDate = new oracle.jbo.domain.Date();
java.util.Date utilDate = new java.util.Date();
long longDate = 1172737018000L;
oraDate.setBytes( DATE.toBytes( new java.sql.Timestamp( longDate ) ) );
utilDate.setTime(longDate);
System.out.printf("oradate %tF %tT %tQ\n" ,
oraDate.getValue(),oraDate.getValue(),oraDate.getValue());
System.out.printf("utildate %tF %tT %tQ\n",
utilDate,utilDate,utilDate);
System.out.println( oraDate.getValue().equals(utilDate) ); // false
System.out.println( utilDate.equals(oraDate.getValue()) ); // true