findbugs

javax.annotation.Nonnull vs assert

孤人 提交于 2019-12-04 23:30:56
I'm using Findbugs and javax.annotation.Nonnull on method parameters. On private methods I usually add an assert line to check for nullness like private void myMethod(@Nonnull String str) { assert str != null .... Latest Netbeans version (7.3rc2) is reporting that the assert check is not necessary (because of the Nonnull annotation). I'm not fully sure this is a Netbeans bug or not. Can the assert line be removed because I specified the @Nonnull annotation ? As far as I understand, the annotation is used only during static analysis while assert is, when enabled, active during execution so the

What is the proper way to use a Logger in a Serializable Java class?

十年热恋 提交于 2019-12-04 16:17:44
问题 I have the following ( doctored ) class in a system I'm working on and Findbugs is generating a SE_BAD_FIELD warning and I'm trying to understand why it would say that before I fix it in the way that I thought I would. The reason I'm confused is because the description would seem to indicate that I had used no other non-serializable instance fields in the class but bar.model.Foo is also not serializable and used in the exact same way (as far as I can tell) but Findbugs generates no warning

Thread Safety framework

橙三吉。 提交于 2019-12-04 13:34:58
问题 The following class is not thread-safe (as proven in Proving the following code not thread safe ) Is there a framework out there that can help with either compile time / run time analysis and tell us that the following is not thread safe? For compile time, ideally in Eclipse the wiggly underline comes up and tells us that the class is not thread safe? For run time, will any the static code analysis catch the class as non-thread-safe? public class LazyInitRace { private ExpensiveObject

Maven execute a goal on build fail / FindBugs

自古美人都是妖i 提交于 2019-12-04 12:17:53
I have integrated FindBugs plugin to fail the build in case of bugs. Then using that brilliant answer I configured FindBugs to generate html reports (xml version is barely readable). The problem is that I have failOnError property set to true , which means that the build would fail in case of bug. ..... <configuration> ..... <failOnError>true</failOnError> </configuration> And then no html report would be generated. I read about Maven build lifecycle and there is no such thing as "Execute on fail" (like finally block in Java). So, are there any possible workarounds? And shouldn't it be out-of

FindBugs error: Write to static field from instance method

那年仲夏 提交于 2019-12-04 12:15:42
问题 I have couple of areas in my application where I get the error while manipulating value of static variable from instance method. "Write to static field from instance method" . If we take multi-threading out of the equation, does this scenario pose any potential issue even if multiple instances write to the same static variable ? 回答1: From the documentation... This instance method writes to a static field. This is tricky to get correct if multiple instances are being manipulated, and generally

How to indicate that member fields are @Nonnull by default?

為{幸葍}努か 提交于 2019-12-04 10:01:23
问题 My question is a follow-up to this one. In past versions of FindBugs, it was possible to use @DefaultAnnotation(Nonnull.class) or @DefaultAnnotationForFields(Nonnull.class) to indicate that all fields in a package should be treated as @Nonnull . In the current version of FindBugs (2.0), @DefaultAnnotation and @DefaultAnnotationForFields are deprecated, and we should all use JSR-305 instead. But JSR-305 doesn't seem to cover everything the (now deprecated) FindBugs annotations cover. The

Is SonarQube Replacement for Checkstyle, PMD, FindBugs?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 07:23:15
问题 We are working on a web project from scratch and are looking at the following static code analysis tools. Conventions (Checkstyle) Bad practices (PMD) Potential bugs (FindBugs) The project is built on Maven. Instead of using multiple tools for the purpose, I was looking at a single flexible solution and came across SonarQube. Is it true that we can achieve the results from Checkstyle, PMD and Findbugs with SonarQube? 回答1: Sonar will run CheckStyle, FindBugs and PMD, as well as a few other

Findbugs issue with ant

蓝咒 提交于 2019-12-04 04:42:02
问题 findbugs: [findbugs] Executing findbugs from ant task [findbugs] Running FindBugs... [findbugs] java.lang.NoClassDefFoundError: org/apache/bcel/classfile/ClassFormtException [findbugs] Caused by: java.lang.ClassNotFoundException: org.apache.bcel.classfile.ClassFormatException [findbugs] at java.net.URLClassLoader$1.run(URLClassLoader.java:202) [findbugs] at java.security.AccessController.doPrivileged(Native Method) [findbugs] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

How to write a customized gradle task to not to ignore Findbugs violations but fail after the analysis is completed

梦想与她 提交于 2019-12-04 03:54:33
问题 I want to write such a gradle task (using the Findbugs plugin) which fails if any Findbugs violations are found but only after completing the analysis . If I do ignoreFailures=true the task won't fail at all and if I make it false the task fails as soon as the first issue is found. I want the task to perform a complete analysis and fail only after it's done if any violations are found. 回答1: You're right, adding ignoreFailures=true will prevent task from failing. Thus this option should be

FindBugs - “may fail to close stream” when using ObjectOutputStream

こ雲淡風輕ζ 提交于 2019-12-04 03:12:14
I have this piece of code, which is to write an Ojbect to a byte array stream: static byte[] toBytes(MyTokens tokens) throws IOException { ByteArrayOutputStream out = null; ObjectOutput s = null; try { out = new ByteArrayOutputStream(); try { s = new ObjectOutputStream(out); s.writeObject(tokens); } finally { try { s.close(); } catch (Exception e) { throw new CSBRuntimeException(e); } } } catch (Exception e) { throw new CSBRuntimeException(e); } finally { IOUtils.closeQuietly(out); } return out.toByteArray(); } However, FindBugs keeps complaining about line: s = new ObjectOutputStream(out);