[ 
https://jira.codehaus.org/browse/QDOX-232?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Robert Scholte updated QDOX-232:
--------------------------------

    Description: 
{code}
public boolean equals(Object obj) {
        if (obj == null) return false;
        JavaMethod m = (JavaMethod) obj;

        if (m.isConstructor() != isConstructor()) return false;

        if (m.getName() == null) return (getName() == null); // this line(215) 
is incorrect
        if (!m.getName().equals(getName())) return false;
        
        if (m.getReturns() == null) return (getReturns() == null); // THIS 
line(218) is incorrect
{code}

They should be: 
{code}
    if(m.getName()==null && getName()!=null) return false;
{code}
and 
{code}
    if(m.getReturns()==null && getReturns()!=null) return false;
{code}
Otherwise, if two methods with same name and return type but different 
parameters will return true, which is incorrect.

Maybe other `equals` have same issue. I think it's a good idea to provide a 
helper method to check, e.g.:
{code}
    public static boolean eq(Object obj1, Object obj2) {
        return obj1==obj2 || (obj1!=null && obj1.equals(obj2);
    }

    if(!eq(m.getName(), getName()) return false;
    if(!eq(m.getReturns(), getReturns()) return false;
{code}

  was:
public boolean equals(Object obj) {
        if (obj == null) return false;
        JavaMethod m = (JavaMethod) obj;

        if (m.isConstructor() != isConstructor()) return false;

        if (m.getName() == null) return (getName() == null); // this line(215) 
is incorrect
        if (!m.getName().equals(getName())) return false;
        
        if (m.getReturns() == null) return (getReturns() == null); // THIS 
line(218) is incorrect


They should be: 

    if(m.getName()==null && getName()!=null) return false;

and 

    if(m.getReturns()==null && getReturns()!=null) return false;

Otherwise, if two methods with same name and return type but different 
parameters will return true, which is incorrect.

Maybe other `equals` have same issue. I think it's a good idea to provide a 
helper method to check, e.g.:

    public static boolean eq(Object obj1, Object obj2) {
        return obj1==obj2 || (obj1!=null && obj1.equals(obj2);
    }

    if(!eq(m.getName(), getName()) return false;
    if(!eq(m.getReturns(), getReturns()) return false;



> DefaultJavaMethod#equals incorrect code
> ---------------------------------------
>
>                 Key: QDOX-232
>                 URL: https://jira.codehaus.org/browse/QDOX-232
>             Project: QDox
>          Issue Type: Bug
>          Components: Java API
>    Affects Versions: 2.0
>            Reporter: Freewind
>            Assignee: Robert Scholte
>              Labels: equals
>
> {code}
> public boolean equals(Object obj) {
>         if (obj == null) return false;
>         JavaMethod m = (JavaMethod) obj;
>         if (m.isConstructor() != isConstructor()) return false;
>         if (m.getName() == null) return (getName() == null); // this 
> line(215) is incorrect
>         if (!m.getName().equals(getName())) return false;
>         
>         if (m.getReturns() == null) return (getReturns() == null); // THIS 
> line(218) is incorrect
> {code}
> They should be: 
> {code}
>     if(m.getName()==null && getName()!=null) return false;
> {code}
> and 
> {code}
>     if(m.getReturns()==null && getReturns()!=null) return false;
> {code}
> Otherwise, if two methods with same name and return type but different 
> parameters will return true, which is incorrect.
> Maybe other `equals` have same issue. I think it's a good idea to provide a 
> helper method to check, e.g.:
> {code}
>     public static boolean eq(Object obj1, Object obj2) {
>         return obj1==obj2 || (obj1!=null && obj1.equals(obj2);
>     }
>     if(!eq(m.getName(), getName()) return false;
>     if(!eq(m.getReturns(), getReturns()) return false;
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to