findbugs

FindBugs : real threat behind EI_EXPOSE_REP

我的未来我决定 提交于 2019-11-29 11:46:34
FindBugs raises a bug called EI_EXPOSE_REP with the following description : EI: May expose internal representation by returning reference to mutable object Returning a reference to a mutable object value stored in one of the object's fields exposes the internal representation of the object. If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Returning a new copy of the object is better approach in many situations. Several questions on SO ( 1 , 2 and 3 ) have

sonar findbugs heap size

三世轮回 提交于 2019-11-29 10:51:42
i am new to sonar. i am running sonar from Jenkins with sonar pulgin. When i am running from jenkins i am getting out of memory exception at findbugs below is the error: Out of memory Total memory: 1037M free memory: 30M Analyzed: D:\Victor\autocreated\webapp\WEB-INF\classes Aux: C:\DOCUME~1\NADBHA~1\LOCALS~1\Temp\findbugs4165854405681394173.jar Aux: C:\DOCUME~1\NADBHA~1\LOCALS~1\Temp\findbugs4688505485649811865.jar Total time: 2:04:49.155s Final Memory: 358M/989M Exception in thread "main" org.sonar.batch.bootstrapper.BootstrapException: org.sonar.api.utils.SonarException: Can not execute

Can findbugs detect unused public methods

五迷三道 提交于 2019-11-29 10:02:50
Is it possible to detect unused methods in a source tree using FindBugs? I see some posts on SO where users are claiming to do that, some others asking how to do this in FB and others where they claim FB cannot do this. Does anyone know for sure how this is done? I am only interested in methods that are not explicitly called from elsewhere, I don't care about reflection. as a member of the FindBugs team I can tell you that unfortunately FindBugs does not do this. If you search through the bug patterns on our website, the only mentions of "unused" detectors is for unused fields . I have a

Set findbugs NotNull as default for all classes under a package

人盡茶涼 提交于 2019-11-29 06:39:26
I have the simple code below for testing the FindBugs @NonNull annotation with Maven. I execute mvn clean install And it correctly fails to build because print(null) violates the non-null condition. You can set NonNull as default for all method parameters inside a class using the class annotation @DefaultAnnotation(NonNull.class) How can I set NonNull as default for all method parameters inside all classes under a given package (and sub-packages)? src/main/java/test/Hello.java package test; import edu.umd.cs.findbugs.annotations.NonNull; public class Hello { static public void print(@NonNull

@Nullable/@NotNull with IntelliJ IDEA, Maven & JSR 305

空扰寡人 提交于 2019-11-29 02:35:10
问题 I really like the code inspection functionalities which are now able with either JSR 305 or Jetbrains' proprietary annotations for IntelliJ. Unfortunately both implementations (JSR 305 and Jetbrains') do not mix well: IntelliJ obviously only understands its own proprietary set of annotations and integrates them quite well. Using Findbugs in my Maven Build, it only supports JSR-305 annotations. The only possible workaround might be to go for JSR-305 and use the Findbugs plugin in IntelliJ. Has

Reliance on default encoding, what should I use and why?

落爺英雄遲暮 提交于 2019-11-29 00:10:33
问题 FindBugs reports a bug: Reliance on default encoding Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behaviour to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly. I used FileReader like this (just a piece of code): public ArrayList<String> getValuesFromFile(File file){ String line; StringTokenizer

In what situations could an empty synchronized block achieve correct threading semantics?

空扰寡人 提交于 2019-11-28 21:13:46
I was looking through a Findbugs report on my code base and one of the patterns that was triggered was for an empty synchronzied block (i.e. synchronized (var) {} ). The documentation says : Empty synchronized blocks are far more subtle and hard to use correctly than most people recognize, and empty synchronized blocks are almost never a better solution than less contrived solutions. In my case it occurred because the contents of the block had been commented out, but the synchronized statement was still there. In what situations could an empty synchronized block achieve correct threading

What's the advantage of making an inner class as static with Java?

荒凉一梦 提交于 2019-11-28 19:16:31
I have an inner class in my Java class. When I run find bugs , it recommends(warns) to make it as static. What's the point of this warning? What's the advantage of making a inner class as static? If the nested class does not access any of the variables of the enclosing class, it can be made static. The advantage of this is that you do not need an enclosing instance of the outer class to use the nested class. An inner class, by default, has an implicit reference to an object of the outer class. If you instantiate an object of this from the code of the outer class, this is all done for you. If

lombok工具中@Data注解问题

Deadly 提交于 2019-11-28 19:09:44
@Data的主要问题,应该是equals()方法,hashCode()方法等的重写问题。 这里,推荐阅读以下,这几篇博客,有助于我们的理解: lombok注解@Data使用在继承类上时出现警告 继承关系中子类使用@Data注解问题 FindBugs引出的Lombok @Data注解使用的问题 来源: oschina 链接: https://my.oschina.net/u/220449/blog/3030183

How to handle a Findbugs “Non-transient non-serializable instance field in serializable class”?

流过昼夜 提交于 2019-11-28 18:21:56
问题 Consider the class below. If I run Findbugs against it it will give me an error ("Non-transient non-serializable instance field in serializable class") on line 5 but not on line 7. 1 public class TestClass implements Serializable { 2 3 private static final long serialVersionUID = 1905162041950251407L; 4 5 private Set<Integer> mySet; // Findbugs error 6 7 private HashSet<Integer> myOtherSet; 8 9 } That's correct because java.util.Set never implements Serializable in its hierarchy and java.util