Active/Severity | Name [expand / collapse] | Sort by: | ||
---|---|---|---|---|
As of Java 5, The following code snippet illustrates this rule: public void doSomething() { int enum = 42; // Non-Compliant }
Repository: squid
![]() ![]() |
||||
The following code snippet: public class MyException extends Error { /* ... */ } // Non-Compliant should be refactored into: public class MyException extends Exception { /* ... */ } // Compliant
Repository: squid
![]() ![]() |
||||
The software uses an HTTP request parameter to construct a pathname that should be within a restricted directory, but it does not properly neutralize absolute path sequences such as "/abs/path" that can resolve to a location that is outside of that directory. See http://cwe.mitre.org/data/definitions/36.html for more information. FindBugs looks only for the most blatant, obvious cases of absolute path traversal. If FindBugs found any, you almost certainly have more vulnerabilities that FindBugs doesn't report. If you are concerned about absolute path traversal, you should seriously consider using a commercial static analysis or pen-testing tool.
Repository: findbugs
![]() ![]() |
||||
The entrySet() method is allowed to return a view of the underlying Map in which a single Entry object is reused and returned during the iteration. As of Java 1.6, both IdentityHashMap and EnumMap did so. When iterating through such a Map, the Entry value is only valid until you advance to the next iteration. If, for example, you try to pass such an entrySet to an addAll method, things will go badly wrong.
Repository: findbugs
![]() ![]() |
||||
While waiting for support of closure in Java, anonymous classes is the most convenient way to inject a behavior without having to create a dedicated class. But those anonymous inner classes should be used only if the behavior can be accomplished in a few lines. With more complex code, a named class is called for. The following code snippet illustrates this rule with a threshold of 5: button.addActionListener(new ActionListener() { // Non-Compliant - 6 lines till closing '}' public void actionPerformed(ActionEvent e) { doSomething1(); doSomething2(); } });
Repository: squid
![]() ![]() |
||||
According to the Java Language Specification: For compatibility with older versions of the Java SE platform, the declaration of a method that returns an array is allowed to place (some or all of) the empty bracket pairs that form the declaration of the array type after the formal parameter list. This obsolescent syntax should not be used in new code. The following code snippet illustrates this rule: public int getVector()[] { /* ... */ } // Non-Compliant public int[] getVector() { /* ... */ } // Compliant public int[] getMatrix()[] { /* ... */ } // Non-Compliant public int[][] getMatrix() { /* ... */ } // Compliant
Repository: squid
![]() ![]() |
||||
Array designators should always be located on the type for better code readability. Otherwise, developers must look both at the type and the variable name to know whether or not a variable is an array. The following code snippet illustrates this rule: int matrix[][]; // Non-Compliant int[] matrix[]; // Non-Compliant int[][] matrix; // Compliant
Repository: squid
![]() ![]() |
||||
Assignments within sub-expressions are hard to spot and therefore make the code less readable.
It is also a common mistake to write Noncompliant Code ExampleSystem.out.println(i = 42); Compliant SolutionSystem.out.println(i == 42); or: i = 42; System.out.println(i); ExceptionsAssignments enclosed in relational expressions are allowed. BufferedReader br = new BufferedReader(/* ... */); String line; while ((line = br.readLine()) != null) { /* ... */ }
Repository: squid
![]() ![]() |
||||
Here are the main reasons why commented code is a code smell :
Repository: squid
![]() ![]() |
||||
One might assume that new BigDecimal(.1) is exactly equal to .1, but it is actually equal to .1000000000000000055511151231257827021181583404541015625. This is so because .1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the long value that is being passed in to the constructor is not exactly equal to .1, appearances notwithstanding. The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal(.1)' is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the (String) constructor be used in preference to this one.
Repository: pmd
![]() ![]() |
||||
Avoid throwing a NullPointerException - it's confusing because most people will assume that the virtual machine threw it. Consider using an IllegalArgumentException instead; this will be clearly seen as a programmer-initiated exception.
Repository: pmd
![]() ![]() |
||||
The Cyclomatic Complexity is measured by the number of (&&, ||) operators and (if, while, do, for, ?:, catch, switch, case, return, throw) statements in the body of a class plus one for each constructor, method (but not getter/setter), static initializer, or instance initializer in the class. The last return stament in method, if exists, is not taken into account. Even when the Cyclomatic Complexity of a class is very high, this complexity might be well distributed among all methods. Nevertheless, most of the time, a very complex class is a class which breaks the Single Responsibility Principle and which should be re-factored to be split in several classes.
Repository: squid
![]() ![]() |
||||
(From JDC Tech Tip): The Swing methods show(), setVisible(), and pack() will create the associated peer for the frame. With the creation of the peer, the system creates the event dispatch thread. This makes things problematic because the event dispatch thread could be notifying listeners while pack and validate are still processing. This situation could result in two threads going through the Swing component-based GUI -- it's a serious flaw that could result in deadlocks or other related threading issues. A pack call causes components to be realized. As they are being realized (that is, not necessarily visible), they could trigger listener notification on the event dispatch thread.
Repository: findbugs
![]() ![]() |
||||
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
Repository: findbugs
![]() ![]() |
||||
This class defines a clone() method but the class doesn't implement Cloneable. There are some situations in which this is OK (e.g., you want to control how subclasses can clone themselves), but just make sure that this is what you intended.
Repository: findbugs
![]() ![]() |
||||
Deprecated
This class defines a From the JavaDoc for the compareTo method in the Comparable interface:
It is strongly recommended, but not strictly required that
This rule is deprecated, use squid:S1210 instead.
Repository: findbugs
![]() ![]() |
||||
Deprecated
This class overrides If you don't think instances of this class will ever be inserted into a HashMap/HashTable,
the recommended public int hashCode() { assert false : "hashCode not designed"; return 42; // any arbitrary constant will do } This rule is deprecated, use squid:S1206 instead.
Repository: findbugs
![]() ![]() |
||||
Deprecated
This class overrides This rule is deprecated, use squid:S1206 instead.
Repository: findbugs
![]() ![]() |
||||
Deprecated
This class defines a If you don't think instances of this class will ever be inserted into a HashMap/HashTable,
the recommended public int hashCode() { assert false : "hashCode not designed"; return 42; // any arbitrary constant will do } This rule is deprecated, use squid:S1206 instead.
Repository: findbugs
![]() ![]() |