1 Reply Latest reply on Aug 24, 2002 12:27 PM by Juha Lindfors

    Bug? EJBLocalObjects.equals() casts crash

    Thorsten Langer Newbie


      JBoss maps all invocations to EJBLocalObject.equals(Object o) to isIdentical(EJBLocalObject a) resp. org.jboss.ejb.plugins.local.LocalProxy.isIdentical(Object a, Object b), which assumes the object a to be an EJBLocalObject (cast!). In the case the original invocation comes from isIdentical(...), this is no problem, but if you drop EJBs and other things in a context, where the equals(Object o) method is invoked with real-world (non-EJB) object you get a crash. "Hashtable.contains(Object o)" is such a context,
      where the EJBLocalObject.equals() method is invoked with arguments possibly different than EJBLocalObjects.


      FIX (for local object only):
      is just two lines in org/jboss/ejb/plugins/local/LocalProxy.java

      * Test the identitiy of an EJBObject.
      * @param a EJBObject.
      * @param b Object to test identity with.
      * @return True if objects are identical.
      * @throws ClassCastException Not an EJBObject instance.
      Boolean isIdentical(final Object a, final Object b)
      if (!(a instanceof EJBLocalObject)) // one
      return Boolean.FALSE; // two
      final EJBLocalObject ejb = (EJBLocalObject)a;
      Boolean isIdentical = Boolean.FALSE;
      if( ejb != null )
      final Object pk = ejb.getPrimaryKey();
      isIdentical = new Boolean(pk.equals(b));
      return isIdentical;