| Active/Severity | Name [expand / collapse] | Sort by: | ||
|---|---|---|---|---|
|
Even though the JavaDoc does not contain a hint about it, Calendars are inherently unsafe for multihtreaded use. Sharing a single instance across thread boundaries without proper synchronization will result in erratic behavior of the application. Under 1.4 problems seem to surface less often than under Java 5 where you will probably see random ArrayIndexOutOfBoundsExceptions or IndexOutOfBoundsExceptions in sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(). You may also experience serialization problems. Using an instance field is recommended. For more information on this see Sun Bug #6231579 and Sun Bug #6178997.
Repository: findbugs
Key: STCAL_STATIC_CALENDAR_INSTANCE
Available since 07 Jan 2014
|
||||
|
As the JavaDoc states, DateFormats are inherently unsafe for multithreaded use. Sharing a single instance across thread boundaries without proper synchronization will result in erratic behavior of the application. You may also experience serialization problems. Using an instance field is recommended. For more information on this see Sun Bug #6231579 and Sun Bug #6178997.
Repository: findbugs
Key: STCAL_STATIC_SIMPLE_DATE_FORMAT_INSTANCE
Available since 07 Jan 2014
|
||||
|
This instance method synchronizes on
private static final String base = "label";
private static int nameCounter = 0;
String constructComponentName() {
synchronized (getClass()) {
return base + nameCounter++;
}
}
Subclasses of
private static final String base = "label";
private static int nameCounter = 0;
String constructComponentName() {
synchronized (Label.class) {
return base + nameCounter++;
}
}
Bug pattern contributed by Jason Mehrens
Repository: findbugs
Key: WL_USING_GETCLASS_RATHER_THAN_CLASS_LITERAL
Available since 07 Jan 2014
|
||||
|
The code synchronizes on a boxed primitive constant, such as an Boolean.
private static Boolean inited = Boolean.FALSE;
...
synchronized(inited) {
if (!inited) {
init();
inited = Boolean.TRUE;
}
}
...
Since there normally exist only two Boolean objects, this code could be synchronizing on the same object as other, unrelated code, leading to unresponsiveness and possible deadlock
Repository: findbugs
Key: DL_SYNCHRONIZATION_ON_BOOLEAN
Available since 07 Jan 2014
|
||||
|
The code synchronizes on a boxed primitive constant, such as an Integer.
private static Integer count = 0;
...
synchronized(count) {
count++;
}
...
Since Integer objects can be cached and shared, this code could be synchronizing on the same object as other, unrelated code, leading to unresponsiveness and possible deadlock
Repository: findbugs
Key: DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE
Available since 07 Jan 2014
|
||||
|
The code synchronizes on an apparently unshared boxed primitive, such as an Integer.
private static final Integer fileLock = new Integer(1);
...
synchronized(fileLock) {
.. do something ..
}
...
It would be much better, in this code, to redeclare fileLock as private static final Object fileLock = new Object();The existing code might be OK, but it is confusing and a future refactoring, such as the "Remove Boxing" refactoring in IntelliJ, might replace this with the use of an interned Integer object shared throughout the JVM, leading to very confusing behavior and potential deadlock.
Repository: findbugs
Key: DL_SYNCHRONIZATION_ON_UNSHARED_BOXED_PRIMITIVE
Available since 07 Jan 2014
|
||||
|
This method synchronizes on a field in what appears to be an attempt to guard against simultaneous updates to that field. But guarding a field gets a lock on the referenced object, not on the field. This may not provide the mutual exclusion you need, and other threads might be obtaining locks on the referenced objects (for other purposes). An example of this pattern would be:
private Long myNtfSeqNbrCounter = new Long(0);
private Long getNotificationSequenceNumber() {
Long result = null;
synchronized(myNtfSeqNbrCounter) {
result = new Long(myNtfSeqNbrCounter.longValue() + 1);
myNtfSeqNbrCounter = new Long(result.longValue());
}
return result;
}
Repository: findbugs
Key: ML_SYNC_ON_FIELD_TO_GUARD_CHANGING_THAT_FIELD
Available since 07 Jan 2014
|
||||
|
The code synchronizes on interned String.
private static String LOCK = "LOCK";
...
synchronized(LOCK) { ...}
...
Constant Strings are interned and shared across all other classes loaded by the JVM. Thus, this could is locking on something that other code might also be locking. This could result in very strange and hard to diagnose blocking and deadlock behavior. See http://www.javalobby.org/java/forums/t96352.html and http://jira.codehaus.org/browse/JETTY-352.
Repository: findbugs
Key: DL_SYNCHRONIZATION_ON_SHARED_CONSTANT
Available since 07 Jan 2014
|
||||
|
Since the field is synchronized on, it seems not likely to be null. If it is null and then synchronized on a NullPointerException will be thrown and the check would be pointless. Better to synchronize on another field.
Repository: findbugs
Key: NP_SYNC_AND_NULL_CHECK_FIELD
Available since 07 Jan 2014
|
||||
|
This method contains a call to
Repository: findbugs
Key: UW_UNCOND_WAIT
Available since 07 Jan 2014
|
||||
|
This class contains similarly-named get and set methods where the set method is synchronized and the get method is not. This may result in incorrect behavior at runtime, as callers of the get method will not necessarily see a consistent state for the object. The get method should be made synchronized.
Repository: findbugs
Key: UG_SYNC_SET_UNSYNC_GET
Available since 07 Jan 2014
|
||||
|
This method calls
Repository: findbugs
Key: NO_NOTIFY_NOT_NOTIFYALL
Available since 07 Jan 2014
|
||||
|
Deprecated
Non-constructor methods should not have the same name as the enclosing class. Example :
public class MyClass {
// this is bad because it is a method
public void MyClass() {}
// this is OK because it is a constructor
public MyClass() {}
}
This rule is deprecated, use squid:S1223 instead.
Repository: pmd
Key: MethodWithSameNameAsEnclosingClass
Available since 07 Jan 2014
|
||||
|
This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
Repository: pmd
Key: NcssTypeCount
Available since 07 Jan 2014
|
||||
|
This code negatives the return value of a compareTo or compare method. This is a questionable or bad programming practice, since if the return value is Integer.MIN_VALUE, negating the return value won't negate the sign of the result. You can achieve the same intended result by reversing the order of the operands rather than by negating the results.
Repository: findbugs
Key: RV_NEGATING_RESULT_OF_COMPARETO
Available since 07 Jan 2014
|
||||
|
Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed. When a block contains a comment, this block is not considered to be empty. The following code snippet illustrates this rule:
void doSomething() {
for (int i = 0; i < 42; i++) // Non-Compliant
{
}
for (int i = 0; i < 42; i++); // Compliant
if (myVar == 4) // Compliant - contains a comment
{
// Do nothing because of X and Y
}
else // Compliant
{
doSomething();
}
try // Non-Compliant
{
}
catch (Exception e) // Compliant
{
// Ignore
}
}
Repository: squid
Key: S00108
Available since 07 Jan 2014
|
||||
|
Nested code blocks can be used to create a new scope and restrict the visibility of the variables defined within. Using this feature in a method typically indicates that it takes on too many responsibilities, and should be refactored into smaller ones. The following code:
public void evaluate(int operator) {
switch (operator) {
/* ... */
case ADD: { // Non-Compliant - nested code block '{' ... '}'
int a = stack.pop();
int b = stack.pop();
int result = a + b;
stack.push(result);
break;
}
/* ... */
}
}
should be refactored into:
public void evaluate(int operator) {
switch (operator) {
/* ... */
case ADD: // Compliant
evaluateAdd();
break;
/* ... */
}
}
private void evaluateAdd() {
int a = stack.pop();
int b = stack.pop();
int result = a + b;
stack.push(result);
}
Repository: squid
Key: S1199
Available since 07 Jan 2014
|
||||
|
Non-static initializers are rarely used, and can be confusing for most developers. When possible, they should be refactored into standard constructors or field initializers. The following code:
class MyClass {
private static final Map
could be refactored using Guava into:
class MyClass {
// Compliant
private static final Map
Repository: squid
Key: S1171
Available since 07 Jan 2014
|
||||
|
This Serializable class defines a non-primitive instance field which is neither transient,
Serializable, or
Repository: findbugs
Key: SE_BAD_FIELD
Available since 07 Jan 2014
|
||||
|
Overloading this method is misleading:
Another name should be picked for the method. The following code:
public void finalize(int someParameter) { // Non-Compliant
/* ... */
}
should be refactored into:
public void someBetterName(int someParameter) { // Compliant
/* ... */
}
Repository: squid
Key: S1175
Available since 07 Jan 2014
|
||||
|
The contract of the The following code snippet illustrates this rule:
public class MyClass {
@Override
public void finalize() { // Non-Compliant
/* ... */
}
}
Repository: squid
Key: S1174
Available since 07 Jan 2014
|
||||