Why do security officers complain about this?

I have a class field that is a data object. Why does checkstyle complain about "writing entry b" and what does it mean? DoSomething1 () is always called before doSomething ()

public class A{ private B b; public void doSomething() { if(b!=null) { b.setYear(2012); b.setDay("Tuesday"); } } public void doSomething1(){ b = new B(); b.setDate(new Date()); } } 
+4
source share
4 answers

This is not the Checkstyle it comes from, but Eclipse itself.

If you select a property of your class, it will show you the appearance of this property in the class with markers in the right scroll bar. They are yellow like Checkstyle markers.

Here, instances will be highlighted where the property is read ("Occurrence X"), and where this property can be written ("Record of occurrence X"), for example, if you pass it to the method as a parameter.

You can see where the message http://grepcode.com/file/repository.grepcode.com/java/eclipse.org/3.5.2/org.eclipse.jdt/ui/3.5.2/org/eclipse/jdt is configured /internal/ui/search/SearchMessages.properties

+3
source

I recently did some research at CheckStyle, FindBugs and others.

With FindBugs (findbugs.sourceforge.net), a common problem is what FindBugs calls "dead storage" when the value is never read, but written only. Could this be a problem?

Your example seems very simplified - can you provide more details?

+2
source

Are you sure this is not your own rule? Not like the one that comes with checkstyle http://checkstyle.sourceforge.net/availablechecks.html If this is your own custom rule, you need to ask who wrote this custom check.

I can only think that the rule is for immutable objects that are much easier to maintain.

+1
source

It's not a mistake. This phenomenon occurs when you place the cursor context on a specific term, in your case "b". When you do this, you will see all occurrences of this term, marked with empty gray rectangles to the right of your code window. You will also see in pale yellow places where this term, if it is a variable, has data written on it.

Try this, click somewhere on the word Exception, and you will see that there are only pale gray, hollow boxes. Now try to create a real variable in your code, you will see gray rectangles and one or more pale yellow boxes.

I have never used this feature myself, but maybe someone considers it valuable.

+1
source

Source: https://habr.com/ru/post/1437445/


All Articles