SDA SE Wiki

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

User Tools

Site Tools


Bug 144 (In the updated findbugs list it is number 14)

FindBugs does not detect this bug.

Inspired by

Original Description

“This statement has a return such as return x++;. A postfix increment/decrement does not impact the value of the expression, so this increment/decrement has no effect. Please verify that this statement does the right thing. ” – 2013-11-24

Detailed Description

A postfix increment in java (such as i++) does the following: - it takes i - stores a copy - adds 1 - returns the copy

That means the expression i++ returns i and not i + 1. <code Java> int i = 5; i++; System.out.println(i); 6 System.out.println(i++); 6 </Code>

Whenever a methods return expression is i++ (or i–) the postfix increment/decrement does effectively nothing since the return value is not changed and the variable will be lost. This is very likely to be a logical error.

Sample Problem Scenario

<code Java> public int getNumber(){

int x = 5;
return x++;

}

public int decrement(int y){

return y--;

} </Code>

Sample Counter Scenario & Sample Fix

<code Java> public int getNumber(){

int x = 5;
x++;
return x;

}

Prefix decrements however do effect the return value of the expression public int decrement(int y){ return –y; } </Code> ===== Evaluation Results ===== ^ Benchmark project ^ Time ^ # Hits ^^ Precision ^^^ Recall ^^^ | || FB | JT | FB | JT | Delta | FB | JT | Delta | | Apache Tomcat |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | Argo UML |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | AWT |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | Jakarta |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | Java IO |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | JHotDraw |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | jrefactory |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | JServlet |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | JUnit |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | Lexi |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | Mapper XML |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | nutch |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | PMD |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | | quickuml |< 1s|0|0| 100% | 100% | 0 | 100% | 100% | 0 | FB = FindBugs, JT = JTransformer, Delta = JTransformer - FindBug All measurements were taken on a machine with the following properties: * JT Version: 4.0.0 * Eclipse Kepler * Windows 8.1 * i5 2,30Ghz * 8 GB Main Memory * SSD Hardrive

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

SEWiki, © 2023