SDA SE Wiki

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

User Tools

Site Tools


Bug Cor 07

Inspired by

Original Description

“This method compares an expression of the form (e & 0) to 0, which will always compare equal. This may indicate a logic error or typo.” – 2013-10-28

Detailed Description

When ever a value is bitwise conjoined with zero (x & 0 ) the result is ALWAYS zero. That means there is no need to compare the result afterwards if it really is zero.

Sample Problem Scenario

<code Java>

	int x = 131;
	if((x & 0) == 0){
		System.out.println("This will always happen");
	}

</Code>

Sample Counter Scenario

<code Java>

	int x = 131;
	if((x | 0) == 0){
		System.out.println("This might happen");
	}

</Code>

Sample Fix

There is no meaningful fix that we can offer. The programmer has to understand herself the logic error or typo and correct it manually.

Evaluation Results

Benchmark project Precision Recall
FB JT Delta FB JT Delta
Apache Tomcat 100% 100% 0 100% 100% 0
Argo UML 100% 100% 0 100% 100% 0
AWT 100% 100% 0 100% 100% 0
Jakarta 100% 100% 0 100% 100% 0
Java IO 100% 100% 0 100% 100% 0
JHotDraw 100% 100% 0 100% 100% 0
jrefactory 100% 100% 0 100% 100% 0
JServlet 100% 100% 0 100% 100% 0
JUnit 100% 100% 0 100% 100% 0
Lexi 100% 100% 0 100% 100% 0
Mapper XML 100% 100% 0 100% 100% 0
nutch 100% 100% 0 100% 100% 0
PMD 100% 100% 0 100% 100% 0
quickuml 100% 100% 0 100% 100% 0

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

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

SEWiki, © 2023