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

User Tools

Site Tools

Bug Cor 8

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 OR operator: | , performs a disjunctive comparison between two integer numbers, bit by bit and returns the resulting integer. For example:

<code Java> short a = 11; 00001011 short b = 33; 00100001 short c = a | b; 00101011 </Code> Would assign c, as result, the value: 43 (1 in binary). When the result of a bitwise |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 a 0 at a particular bit, the OR operator requires that both of the corresponding bits in the parameters are 0. If this situation is detected, its very likely due to a logic error in the code or an incorrect usage of the AND operator where AND(&) should have been used. ===== Sample Problem Scenario ===== <code Java> public class BitwiseErrors { int j =0; if ( (j | 0) == 1){ The comparison will be unequal.

		System.out.print("Never printed");
		System.out.print("Incompatible mask");

} </Code>

Evaluation Results

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

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

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

SEWiki, © 2023