SDA SE Wiki

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

User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
teaching:labs:mdse:2013:bug_descriptions:jt-bug-cor69 [2014/03/27 11:58]
malte.mauelshagen
teaching:labs:mdse:2013:bug_descriptions:jt-bug-cor69 [2018/05/09 01:59] (current)
Line 1: Line 1:
 +====== JT Bug number Jt-Cor-69 ======
 +
 +<note warning>
 +FindBugs does not detect this bug.
 +</​note>​
 +
 +
 +
 +===== Inspired by =====
 +
 +  * [[http://​findbugs.sourceforge.net/​bugDescriptions.html#​IM_MULTIPLYING_RESULT_OF_IREM | IM_MULTIPLYING_RESULT_OF_IREM]]
 +
 +===== Original Description =====
 +
 +"The code multiplies the result of an integer remaining by an integer constant. Be sure you don't have your operator precedence confused. For example i % 60 * 1000 is (i % 60) * 1000, not i % (60 * 1000)."​
 +
 +===== Detailed Description =====
 +{{:​teaching:​labs:​mdse:​2013:​bug_descriptions:​operator-pre.jpg|}}
 +
 +For Java **remainders** and **multiplications** are on the same level when it comes to operator precedence (i.e. whatever term stands further left is computed first). That might be not very intuitive or widely known and can therefore lead to errors. Programmers should always indicate the order they want to have using parentheses.
 +
 +===== Sample Problem Scenario =====
 +
 +
 +<code Java>
 + 
 +     public static void main(String []args) {
 +     int i=230;
 +        ​System.out.println(i % 60 * 1000); ​
 +     }
 +  
 +
 +</​Code>​
 +
 +===== Sample Counter Scenario =====
 +
 +
 +<code Java>
 + 
 +     public static void main(String []args) {
 +     int i=230;
 +        ​System.out.println("​i % 60 * 1000"​);​
 +                       ​System.out.println(60 % 1000); ​
 +                       ​System.out.println(i * 60);
 +                       ​System.out.println(i * 60 + 1000);
 +                       ​System.out.println(i * (60 % 1000)); ​   ​
 +     }
 +  
 +
 +</​Code>​
 +
 +===== Sample Fix =====
 +
 +It's hard to provide a fix since it is not sure what the programmer wants. In any case she should specify the operations using Parentheses. One of the following "​fixes"​ can be applied:
 +<code Java>
 +              public static void main(String []args) {
 +     int i=230;
 +        ​System.out.println((i % 60) * 1000); ​
 +     }
 +</​Code>​
 +<code Java>
 +              public static void main(String []args) {
 +     int i=230;
 +        ​System.out.println(i % (60 * 1000)); ​
 +     }
 +</​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  | /* Done! */
 +|  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-cor69.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019