Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider Java v3.0

...

Code Block
int i = // initialize to user supplied value 
if ((i >&gt;= 0) &amp;&amp; ((i++) <&lt;= Integer.MAX_VALUE)) {
  // ...
}

...

Code Block
bgColor#ffcccc
class BadRenameFile {
  public static void main(String[] args) {
    File fOriginal = new File("&quot;original.txt"&quot;);
    File fNew = new File("&quot;new.txt"&quot;);
    if(fOriginal.exists() || fOriginal.renameTo(fNew)) {
      // do something with fNew
      fNew.delete();
    }
  }
} 

...

Code Block
bgColor#ccccff
class RenameFile {
  public static void main(String[] args) {
    File fOriginal = new File("&quot;original.txt"&quot;);
    File fNew = new File("&quot;new.txt"&quot;);

    if(!fOriginal.exists() || !fOriginal.renameTo(fNew)) {
      // handle error
    }
    // do something with fNew
    if(!fNew.delete()) {
      // handle error  
    }
  }
} 

...

Code Block
if (data != null &amp;&amp; i <&lt; data.length &amp;&amp; data[i] != -1) ... 

This code snippet sequentially executes the subexpressions while avoiding an array indexing exception resulting from the checks that execute prior to the last subexpression.

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

Wiki Markup
\[[JLS 05|AA. Java References#JLS 05]\] Sections [15.23|http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.23] "&quot;Conditional-And Operator &amp;&amp;&"quot; and [15.24|http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.24] "&quot;Conditional-Or Operator ||"&quot;
\[[Flanagan 05|AA. Java References#Flanagan 05]\] 2.5.6. Boolean Operators

...

EXP05-J. Be careful of autoboxing when removing elements from a Collection      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;04. Expressions (EXP)      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EXP07-J. Do not diminish the benefits of constants by assuming their values in expressions