This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Created attachment 114564 [details] A Java class (fully implements MCRecipe, not included), wherein the reported bug triggers In the attached file BHRecipeAdapter, NetBeans claims that the "grid" array is only read and never written to, even though the constructor and one method write to it and one method reads it.
repriducible
I too, have encountered this. I have a class with a private set that shows an unbalanced collection, even though there is one method in the class (actually an instance method of the object) that adds to the set, and another that removes from the set.
Fix for the array case: http://hg.netbeans.org/jet-main/rev/327ce9229aad sparkee, if you would have a reproducible test case of the Set case that you could attach here, that would be awesome. Otherwise, what is the declared type of the variable on which the bug manifests? E.g. java.util.Set, java.util.HashSet, java.util.NavigableSet, etc. Thank you very much.
Integrated into 'main-golden' Changeset: http://hg.netbeans.org/main-golden/rev/327ce9229aad User: Jan Lahoda <jlahoda@netbeans.org> Log: #206855: ignoring arrays of arrays in the unbalanced hint.
Created attachment 114709 [details] Code snippet that improperly causes "Collection only added to, never read" hint. As requested,a code snippet that improperly hints.
My attachment is hacked out of a piece of code for my project at work if it looks weird.
Integrated into 'main-golden' Changeset: http://hg.netbeans.org/main-golden/rev/43558d0c447e User: Jan Lahoda <jlahoda@netbeans.org> Log: #206855: if the result of the "add" method is checked, then it should be used as both write and read to/from the collection.
(In reply to comment #7) > Integrated into 'main-golden' > Changeset: http://hg.netbeans.org/main-golden/rev/43558d0c447e > User: Jan Lahoda <jlahoda@netbeans.org> > Log: #206855: if the result of the "add" method is checked, then it should be > used as both write and read to/from the collection. I would suggest (presuming the code is not already doing this) that you consider checking the results of the following with the same rationale: remove(E e); addAll(Collection<E> c); removalAll(Collection<E> c); retainAll(Collection<E> c); These are also technically "reads" of a collection.
(In reply to comment #8) > (In reply to comment #7) > > Integrated into 'main-golden' > > Changeset: http://hg.netbeans.org/main-golden/rev/43558d0c447e > > User: Jan Lahoda <jlahoda@netbeans.org> > > Log: #206855: if the result of the "add" method is checked, then it should be > > used as both write and read to/from the collection. > > I would suggest (presuming the code is not already doing this) that you > consider checking the results of the following with the same rationale: > remove(E e); > addAll(Collection<E> c); > removalAll(Collection<E> c); > retainAll(Collection<E> c); > > These are also technically "reads" of a collection. The patch ensures that if the result of any add, addAll and set methods are checked, they are considered to both read and write the collection. The handling of remove&retain methods is a bit different (and somewhat counter-intuitive): the remove&retain methods are not considered to be writing the collection at all, they are handled in the same way as methods that read from the collection. The reason is that if nothing is added to a collection (using add/addAll), there is nothing to remove anyway, and the remove&retain methods have no effect. Thanks for the report and testcase.
verified
releases71_fixes: http://hg.netbeans.org/releases/rev/6ea4f40f964e http://hg.netbeans.org/releases/rev/0bb9e3a2f8dd
Integrated into 'releases', will be available in build *201202072200* or newer. Wait for official and publicly available build. Changeset: http://hg.netbeans.org/releases/rev/0bb9e3a2f8dd User: Jan Lahoda <jlahoda@netbeans.org> Log: #206855: ignoring arrays of arrays in the unbalanced hint. (transplanted from 327ce9229aad56a678da8857f00c38051618b048)
verified in patch1
*** Bug 208547 has been marked as a duplicate of this bug. ***