SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


Bug Cor 43

Inspired by

Original Description

This class defines an equals() method, that doesn't override the normal equals(Object) method defined in the base java.lang.Object class. The class should probably define a boolean equals(Object) method. – 2013-10-13

Detailed Description

Every method named equals must have the signature public boolean equals(Object) in order to override the equals method from java.lang.Object. So, it is considered as a bug if you create a method named equals, having

  • a different number of parameters or
  • a parameter of a different type

Sample Problem Scenario

<code Java> private void equals(){

} </Code>

<code Java> public boolean equals(Object… o){

     return false;

} </Code>

<code Java> public boolean equals(Object o, int i){

     return false;

} </Code>

<code Java> public boolean equals(int i){

     return false;

} </Code>

Sample Fix

An idea to “fix” the problem is by renaming the methods so they can be distinguished from the actual equals() method. <code Java>

private void myEquals(){

	
}

public boolean myEquals(Object o, int i){
	return false;
	
}

</Code>

Evaluation Results

Benchmark project Precision Recall
FB JT Delta FB JT Delta
Project … …% …% …% …% …% …%
Project … …% …% …% …% …% …%

FB = FindBugs, JT = JTransformer, Delta = JTransformer - FindBugs

Apache Tomcat

FindBug→Finds invocations and not the actual methods (2) and does not even follow control flow (our own test case)

JT→ Finds the actual declarations of the methods (20)

teaching/labs/mdse/2013/bug_descriptions/jt-bug-cor43.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2023