Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple, general-interest, code-analyzers based, Java questions
    primarykey
    data
    text
    <p>OK, after reviewing some code with <a href="http://pmd.sourceforge.net" rel="nofollow noreferrer"> PMD</a> and <a href="http://findbugs.sourceforge.net/" rel="nofollow noreferrer">FindBugs</a> code analyzers, i was able to do great changes on the reviewed code. However, there are some things i don't know how to fix. I'll iterate them bellow, and (for better reference) i will give each question a number. Feel free to answer to any/all of them. Thanks for your patience.</p> <p>1. Even tough i have removed some of the rules, the associated warnings are still there, after re-evaluate the code. Any idea why?</p> <hr> <p>2. Please look at the declarations : </p> <pre><code> private Combo comboAdress; private ProgressBar pBar; </code></pre> <p>and the references to objects by getters and setters : </p> <pre><code> private final Combo getComboAdress() { return this.comboAdress; } private final void setComboAdress(final Combo comboAdress) { this.comboAdress = comboAdress; } private final ProgressBar getpBar() { return this.pBar; } private final void setpBar(final ProgressBar pBar) { this.pBar = pBar; } </code></pre> <p>Now, i wonder why the first declaration don't give me any warning on PMD, while the second gives me the following warning : </p> <pre><code>Found non-transient, non-static member. Please mark as transient or provide accessors. </code></pre> <p>More details on that warning <a href="http://pmd.sourceforge.net/rules/javabeans.html#BeanMembersShouldSerialize" rel="nofollow noreferrer"> here</a>.</p> <hr> <p>3. Here is another warning, also given by PMD : </p> <pre><code> A method should have only one exit point, and that should be the last statement in the method </code></pre> <p>More details on that warning <a href="http://pmd.sourceforge.net/rules/controversial.html#OnlyOneReturn" rel="nofollow noreferrer"> here</a>.</p> <p>Now, i agree with that, but what if i write something like this : </p> <pre><code>public void actionPerformedOnModifyComboLocations() { if (getMainTree().isFocusControl()) { return; } ....//do stuffs, based on the initial test } </code></pre> <p>I tend to agree with the rule, but if performance of the code suggest multiple exit points, what should i do?</p> <hr> <p>4. PMD gives me this :</p> <pre><code>Found 'DD'-anomaly for variable 'start_page' (lines '319'-'322'). </code></pre> <p>when i declare something like : </p> <pre><code>String start_page = null; </code></pre> <p>I get rid of this info (level of warning is info) if i remove the assignment to null, but..i got an error from IDE, saying that the variable could be uninitialized, at some point later in the code. So, i am kind of stuck with that. Supressing the warning is the best you can do?</p> <hr> <p>5. PMD Warning : </p> <pre><code>Assigning an Object to null is a code smell. Consider refactoring. </code></pre> <p>This is the case of a singletone use of GUI components or the case of a method who returns complex objects. Assigning the result to null in the catch() section it's justified by the need to avoid the return of an incomplete/inconsistent object. Yes, NullObject should be used, but there are cases where i don't want to do that. Should i supress that warning then?</p> <hr> <p>6. FindBugs warning #1: </p> <pre><code>Write to static field MyClass.instance from instance method MyClass.handleEvent(Event) </code></pre> <p>in the method </p> <pre><code>@Override public void handleEvent(Event e) { switch (e.type) { case SWT.Dispose: { if (e.widget == getComposite()) { MyClass.instance = null; } break; } } } </code></pre> <p>of the static variable </p> <pre><code>private static MyClass instance = null; </code></pre> <p>The variable allows me to test whether the form is already created and visible or not, and i need to force the re-creation of the form, in some cases. I see no other alternative here. Any insights? (MyClass implements Listener, hence the overrided handleEvent() method).</p> <hr> <p>7. FindBugs warning #2:</p> <pre><code>Class MyClass2 has a circular dependency with other classes </code></pre> <p>This warning is displayed based on simple imports of other classes. Do i need to refactor those imports to make this warning go away? Or the problem relies in MyClass2?</p> <p>OK, enough said for now..expect an update, based on more findings and/or your answers. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload