SDA SE Wiki

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

User Tools

Site Tools


Bug Cor 6

Inspired by

Original Description

“This method compares an expression of the form (e & C) to D, which will always compare unequal due to the specific values of constants C and D. This may indicate a logic error or typo.

Detailed Description

The bitwise AND operator: & , performs a conjuntive comparison between two integer numbers, bit by bit and returns the resulting integer. For example:

short a = 11; 	// 00001011
short b = 33; 	// 00100001
short c = a & b; 	// 00000001

Would assign c, as result, the value: 1 (1 in binary).

When the result of a bitwise AND operation is compared with another value, which can be determined before runtime and one of the compared numbers can also be determined before runtime, it is possible to detect if the comparison will always evaluate to false. This is owning to the fact that, in order to produce 1 at a particular bit, the AND operator requires that both of the corresponding bits in the parameters are 1. If a 0 is detected in one operand, its very likely due to a logic error in the code or an incorrect usage of the AND operator where OR (|) should have been used.

Sample Problem Scenario

public class BitwiseErrors {
	int j =1;
 
 
		if ( (j & 0) == 1){                // The comparison will be unequal. 
			System.out.print("Never printed");
		}else
		{        
			System.out.print("Incompatible mask");
		}
 
}

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-cor6.txt · Last modified: 2019/06/19 11:27 by Günter Kniesel

SEWiki, © 2023