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
teaching:labs:mdse:2013:bug_descriptions:jt-bug-cor10 [2018/05/09 01:59]
127.0.0.1 external edit
teaching:labs:mdse:2013:bug_descriptions:jt-bug-cor10 [2019/06/28 19:31] (current)
Günter Kniesel
Line 1: Line 1:
 ====== Cor 10 ====== ====== Cor 10 ======
-<note warning> 
-FindBugs does not detect this bug. 
-</​note>​ 
- 
- 
  
 ===== Inspired by ===== ===== Inspired by =====
Line 12: Line 7:
 ===== Original Description ===== ===== Original Description =====
  
-" This method compares an expression such as +"This method compares an expression such as ''​((event.detail & SWT.SELECTED) > 0)''​. ​Using bit arithmetic and then comparing with the greater than operator can lead to unexpected results (of course depending on the value of SWT.SELECTED). If SWT.SELECTED is a negative number, this is a candidate for a bug. Even when SWT.SELECTED is not negative, it seems good practice to use '!= 0' instead of '> 0'. -- //Boris Bokowski//, ​2013-10-31"  ​
-  ​((event.detail & SWT.SELECTED) > 0) +
-Using bit arithmetic and then comparing with the greater than operator can lead to unexpected results (of course depending on the value of SWT.SELECTED). If SWT.SELECTED is a negative number, this is a candidate for a bug. Even when SWT.SELECTED is not negative, it seems good practice to use '!= 0' instead of '> 0'. +
- +
-Boris Bokowski " ​-- 2013-10-31 ​+
  
 ===== Detailed Description ===== ===== Detailed Description =====
Line 24: Line 15:
    
  
-===== Sample ​Problem Scenario =====+===== Problem Scenario =====
  
  
 <code Java> <code Java>
- if ((x & y) > 0) {+ if ((x & y) > 0) ...  
 +</​code>​ 
 +If one of the values that are input to the & operator is statically known to be negative at this point (e.g. a constant, or guarded before by a test for being <0), then the above should be marked as an **ERROR**. Otherwise it should be *WARNED* that this might be an error and *SUGGESTED* (quick-fix) that an explicit != comparison would be easier to understand. ​
  
- } 
-</​Code>​ 
- 
-<code Java> 
- if ((4 & 5) > 0) { 
- 
- } 
-</​Code>​ 
  
 ===== Sample Counter Scenario ===== ===== Sample Counter Scenario =====
  
 <code Java> <code Java>
- if ((x & y) > 3) + if ((x & y) > 3) ... 
- +</code
- } +If the comparison is to a constant bigger than 0 (or to a statically unknown value) no error or waring must be produced. ​
-</Code+
  
 ===== Sample Fix ===== ===== Sample Fix =====
Line 54: Line 37:
  
  }  }
-</Code>+</code>
 ===== Evaluation Results ===== ===== Evaluation Results =====
 +
 +<note warning>
 +I doubt the numbers below are correct and rather guess the author did not understand the notions of precision and recall. ​
 +</​note>​
  
  
teaching/labs/mdse/2013/bug_descriptions/jt-bug-cor10.txt · Last modified: 2019/06/28 19:31 by Günter Kniesel

SEWiki, © 2019