...
Code Block |
---|
int i = // initialize to user supplied value if ((i >>= 0) && ((i++) <<= Integer.MAX_VALUE)) { // ... } |
...
Code Block | ||
---|---|---|
| ||
class BadRenameFile { public static void main(String[] args) { File fOriginal = new File(""original.txt""); File fNew = new File(""new.txt""); if(fOriginal.exists() || fOriginal.renameTo(fNew)) { // do something with fNew fNew.delete(); } } } |
...
Code Block | ||
---|---|---|
| ||
class RenameFile { public static void main(String[] args) { File fOriginal = new File(""original.txt""); File fNew = new File(""new.txt""); if(!fOriginal.exists() || !fOriginal.renameTo(fNew)) { // handle error } // do something with fNew if(!fNew.delete()) { // handle error } } } |
...
Code Block |
---|
if (data != null && i << data.length && 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] ""Conditional-And Operator &&&"quot; and [15.24|http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.24] ""Conditional-Or Operator ||"" \[[Flanagan 05|AA. Java References#Flanagan 05]\] 2.5.6. Boolean Operators |
...
EXP05-J. Be careful of autoboxing when removing elements from a Collection 04. Expressions (EXP) EXP07-J. Do not diminish the benefits of constants by assuming their values in expressions