# CodeNarc Report

Report title: | Sample Project
Date: | Feb 17, 2015 8:58:07 PM
Generated with: | CodeNarc v0.23

## Summary

Package | Total Files | Files with Violations | Priority 1 | Priority 2 | Priority 3
--- | --- | --- | --- | --- | ---
All Packages | 10 | 6 | - | - | 8
<Root> | 7 | 3 | - | - | 3
io | 3 | 3 | - | - | 5

## Package: <Root>

### ➥ ModifiersUtilTest.groovy

Rule Name | Priority | Line # | Source Line / Message
--- | --- | --- | ---
MisorderedStaticImports | 3 | 20 | [SRC]import static org.codenarc.test.TestUtil.shouldFailWithM..geContaining [MSG]Static imports should appear before normal imports

### ➥ PropertyUtilTest.groovy

Rule Name | Priority | Line # | Source Line / Message
--- | --- | --- | ---
MisorderedStaticImports | 3 | 22 | [SRC]import static org.codenarc.test.TestUtil.shouldFail [MSG]Static imports should appear before normal imports

### ➥ SourceCodeUtilTest.groovy

Rule Name | Priority | Line # | Source Line / Message
--- | --- | --- | ---
MisorderedStaticImports | 3 | 27 | [SRC]import static org.codenarc.test.TestUtil.shouldFail [MSG]Static imports should appear before normal imports

## Package: io

### ➥ ClassPathResourceTest.groovy

Rule Name | Priority | Line # | Source Line / Message
--- | --- | --- | ---
MisorderedStaticImports | 3 | 21 | [SRC]import static org.codenarc.test.TestUtil.shouldFail [MSG]Static imports should appear before normal imports
MisorderedStaticImports | 3 | 22 | [SRC]import static org.codenarc.test.TestUtil.shouldFailWithM..geContaining [MSG]Static imports should appear before normal imports

### ➥ DefaultResourceFactoryTest.groovy

Rule Name | Priority | Line # | Source Line / Message
--- | --- | --- | ---
MisorderedStaticImports | 3 | 22 | [SRC]import static org.codenarc.test.TestUtil.shouldFailWithM..geContaining [MSG]Static imports should appear before normal imports

### ➥ UrlResourceTest.groovy

Rule Name | Priority | Line # | Source Line / Message
--- | --- | --- | ---
MisorderedStaticImports | 3 | 21 | [SRC]import static org.codenarc.test.TestUtil.shouldFail [MSG]Static imports should appear before normal imports
MisorderedStaticImports | 3 | 22 | [SRC]import static org.codenarc.test.TestUtil.shouldFailWithM..geContaining [MSG]Static imports should appear before normal imports

## Rule Descriptions

# | Rule Name | Description
--- | --- | ---
1 | AssertWithinFinallyBlock | Checks for assert statements within a finally block. An assert can throw an exception, hiding the original exception, if there is one.
2 | AssignmentInConditional | An assignment operator (=) was used in a conditional test. This is usually a typo, and the comparison operator (==) was intended.
3 | BigDecimalInstantiation | Checks for calls to the BigDecimal constructors that take a double parameter, which may result in an unexpected BigDecimal value.
4 | BitwiseOperatorInConditional | Checks for bitwise operations in conditionals, if you need to do a bitwise operation then it is best practive to extract a temp variable.
5 | BooleanGetBoolean | This rule catches usages of java.lang.Boolean.getBoolean(String) which reads a boolean from the System properties. It is often mistakenly used to attempt to read user input or parse a String into a boolean. It is a poor piece of API to use; replace it with System.properties['prop'].
6 | BrokenNullCheck | Looks for faulty checks for null that can cause a NullPointerException.
7 | BrokenOddnessCheck | The code uses x % 2 == 1 to check to see if a value is odd, but this won't work for negative numbers (e.g., (-5) % 2 == -1). If this code is intending to check for oddness, consider using x & 1 == 1, or x % 2 != 0.
8 | ClassForName | Using Class.forName(...) is a common way to add dynamic behavior to a system. However, using this method can cause resource leaks because the classes can be pinned in memory for long periods of time.
9 | ComparisonOfTwoConstants | Checks for expressions where a comparison operator or equals() or compareTo() is used to compare two constants to each other or two literals that contain only constant values., e.g.: 23 == 67, Boolean.FALSE != false, 0.17 <= 0.99, "abc" > "ddd", [a:1] <=> [a:2], [1,2].equals([3,4]) or [a:false, b:true].compareTo(['a':34.5, b:Boolean.TRUE].
10 | ComparisonWithSelf | Checks for expressions where a comparison operator or equals() or compareTo() is used to compare a variable to itself, e.g.: x == x, x != x, x <=> x, x < x, x =>= x, x.equals(x) or x.compareTo(x), where x is a variable.
11 | ConstantAssertExpression | Checks for assert statements where the assert boolean condition expression is a constant or literal value.
12 | ConstantIfExpression | Checks for if statements with a constant value for the if expression, such as true, false, null, or a literal constant value.
13 | ConstantTernaryExpression | Checks for ternary expressions with a constant value for the boolean expression, such as true, false, null, or a literal constant value.
14 | DeadCode | Dead code appears after a return statement or an exception is thrown. If code appears after one of these statements then it will never be executed and can be safely deleted.
15 | DoubleNegative | There is no point in using a double negative, it is always positive. For instance !!x can always be simplified to x. And !(!x) can as well.
16 | DuplicateCaseStatement | Check for duplicate case statements in a switch block, such as two equal integers or strings.
17 | DuplicateImport | Duplicate import statements are unnecessary.
18 | DuplicateMapKey | A map literal is created with duplicated key. The map entry will be overwritten.
19 | DuplicateSetValue | A Set literal is created with duplicate constant value. A set cannot contain two elements with the same value.
20 | EmptyCatchBlock | In most cases, exceptions should not be caught and ignored (swallowed).
21 | EmptyClass | Reports classes without methods, fields or properties. Why would you need a class like this?
22 | EmptyElseBlock | Empty else blocks are confusing and serve no purpose.
23 | EmptyFinallyBlock | Empty finally blocks are confusing and serve no purpose.
24 | EmptyForStatement | Empty for statements are confusing and serve no purpose.
25 | EmptyIfStatement | Empty if statements are confusing and serve no purpose.
26 | EmptyInstanceInitializer | An empty class instance initializer was found. It is safe to remove it.
27 | EmptyMethod | A method was found without an implementation. If the method is overriding or implementing a parent method, then mark it with the @Override annotation.
28 | EmptyStaticInitializer | An empty static initializer was found. It is safe to remove it.
29 | EmptySwitchStatement | Empty switch statements are confusing and serve no purpose.
30 | EmptySynchronizedStatement | Empty synchronized statements are confusing and serve no purpose.
31 | EmptyTryBlock | Empty try blocks are confusing and serve no purpose.
32 | EmptyWhileStatement | Empty while statements are confusing and serve no purpose.
33 | EqualsAndHashCode | If either the boolean equals(Object) or the int hashCode() methods are overridden within a class, then both must be overridden.
34 | EqualsOverloaded | The class has an equals method, but the parameter of the method is not of type Object. It is not overriding equals but instead overloading it.
35 | ExplicitGarbageCollection | Calls to System.gc(), Runtime.getRuntime().gc(), and System.runFinalization() are not advised. Code should have the same behavior whether the garbage collection is disabled using the option -Xdisableexplicitgc or not. Moreover, "modern" jvms do a very good job handling garbage collections. If memory usage issues unrelated to memory leaks develop within an application, it should be dealt with JVM options rather than within the code itself.
36 | ForLoopShouldBeWhileLoop | A for loop without an init and update statement can be simplified to a while loop.
37 | HardCodedWindowsFileSeparator | This rule finds usages of a Windows file separator within the constructor call of a File object. It is better to use the Unix file separator or use the File.separator constant.
38 | HardCodedWindowsRootDirectory | This rule find cases where a File object is constructed with a windows-based path. This is not portable, and using the File.listRoots() method is a better alternative.
39 | ImportFromSamePackage | An import of a class that is within the same package is unnecessary.
40 | ImportFromSunPackages | Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.
41 | IntegerGetInteger | This rule catches usages of java.lang.Integer.getInteger(String, ...) which reads an Integer from the System properties. It is often mistakenly used to attempt to read user input or parse a String into an Integer. It is a poor piece of API to use; replace it with System.properties['prop'].
42 | MisorderedStaticImports | Static imports should never be declared after nonstatic imports.
43 | MultipleUnaryOperators | Checks for multiple consecutive unary operators. These are confusing, and are likely typos and bugs.
44 | NoWildcardImports | Wildcard imports, static or otherwise, should not be used.
45 | RandomDoubleCoercedToZero | The Math.random() method returns a double result greater than or equal to 0.0 and less than 1.0. If you coerce this result into an Integer or int, then it is coerced to zero. Casting the result to int, or assigning it to an int field is probably a bug.
46 | RemoveAllOnSelf | Don't use removeAll to clear a collection. If you want to remove all elements from a collection c, use c.clear, not c.removeAll(c). Calling c.removeAll(c) to clear a collection is less clear, susceptible to errors from typos, less efficient and for some collections, might throw a ConcurrentModificationException.
47 | ReturnFromFinallyBlock | Returning from a finally block is confusing and can hide the original exception.
48 | ThrowExceptionFromFinallyBlock | Throwing an exception from a finally block is confusing and can hide the original exception.
49 | UnnecessaryGroovyImport | A Groovy file does not need to include an import for classes from java.lang, java.util, java.io, java.net, groovy.lang and groovy.util, as well as the classes java.math.BigDecimal and java.math.BigInteger.
50 | UnusedImport | Imports for a class that is never referenced within the source file is unnecessary.