How to suppress FindBugs warnings for fields or local variables?

@SuppressFBWarnings on a field only suppresses findbugs warnings reported for that field declaration, not every warning associated with that field. For example, this suppresses the “Field only ever set to null” warning: @SuppressFBWarnings(“UWF_NULL_FIELD”) String s = null; I think the best you can do is isolate the code with the warning into the smallest method … Read more

@Nullable input in Google Guava Function interface triggers FindBugs warning

Your implementation is wrong 😉 Basically docs says (I’ll paraphrase and emphasise): @throws NullPointerException if input is null and the concrete function implementation does not accept null arguments By implementing your function you must decide if it accepts nulls or not. In first case: private static final class Example implements Function<MyBean, String> { @Override @Nullable … Read more

Switch without break

Findbugs is flagging up that falling through from one case to the next is generally not a good idea if there’s any code in the first one (although sometimes it can be used to good effect). So when it sees the second case and no break, it reports the error. So for instance: switch (foo) … Read more

Findbugs issue with “Boxing/unboxing to parse a primitive” with Integer.valueOf(String)

The issue is that Integer.valueOf returns an Integer, not an int, but your someOtherMethod expects an int. Findbugs is basically warning you that you’re doing it a long-winded way that involves potentially creating an object (the Integer) that you don’t need which you’re then immediately going to unbox by passing it to someOtherMethod(int), e.g.: String … Read more

@GuardedBy annotation with java.util.concurrent.locks.ReadWriteLock

At the time of this writing, @GuardedBy isn’t fully implemented by Findbugs, and is mostly just for documentation. (It is partially implemented.) I always use @GuardedBy(“readwritelock”) or the object that I use to synchronize. For example of the latter: class Example { private Object lock = new Object(); @GuardedBy(“lock”) private Stuff innards = …; public … Read more

ResultSet not closed when connection closed?

One problem with ONLY closing the connection and not the result set, is that if your connection management code is using connection pooling, the connection.close() would just put the connection back in the pool. Additionally, some database have a cursor resource on the server that will not be freed properly unless it is explicitly closed.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)