Skip to content

CrmLookupEntity.equals(Object) issues #3

Closed as not planned
Closed as not planned
@rgoldberg

Description

@rgoldberg

In CrmLookupEntity.equals(Object), if o == null, you get a NullPointerException.

If ! (o instanceof CrmLookupEntity), you get a GroovyCastException

Existing code:

boolean equals(o) {
    if (this.is(o)) return true
    //if (getClass() != o.class) return false
    // TODO How can we handle Hibernate proxies here without importing org.hibernate?
    // grails.plugins.crm.order.CrmOrderStatus_$$_javassist_7
    // grails.plugins.crm.order.CrmOrderStatus

    CrmLookupEntity that = (CrmLookupEntity) o

    if (this.id != that.id) return false
    if (this.orderIndex != that.orderIndex) return false
    if (this.name != that.name) return false
    if (this.param != that.param) return false

    return true
}

The following commented line should be replaced:

    //if (getClass() != o.class) return false

by something like:

    if (o == null || getClass() != o.class) return false

or:

    if (o == null || ! getClass().isAssignableFrom(o.class)) return false

A NullPointerException will also be thrown by CrmContactAddress.equals(Object), so you should check all of the equals(Object) methods in all of the crm classes.

If you want, the following article is useful for implementing robust equals(Object) methods:

http://www.artima.com/lejava/articles/equality.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions