nmatt opened a new issue, #4782:
URL: https://github.com/apache/netbeans/issues/4782

   ### Apache NetBeans version
   
   Apache NetBeans 15
   
   ### What happened
   
   Example Java source code:
   
   ```java
   public final class Example
   {
       private final List<String> items;  // (*)
   
       public Example(List<String> items)
       {
           // defensive copy:
           this.items = Collections.unmodifiableList(new ArrayList<>(items));
       }
   
       public List<String> getItems()
       {
           return items;
       }
   
       @Override
       public String toString()
       {
           return items.isEmpty() ? "(no items)" : String.join(", ", items);
       }
   }
   ```
   
   NetBeans shows a warning "the collection is never added to" on the `items` 
field (*), This is triggered by the `isEmpty()` invocation in `toString()`. 
However, NetBeans should either notice that this is a read-only collection 
(difficult), or else notice that the field is exposed to client code through 
`getItems()`, which allows client code to (attempt to) add to the list.
   
   NetBeans 12.2 (which I used previously) does not show that warning, although 
it does support the same hint ("Unbalanced read/write with collections"). So 
this appears to be a regression.
   
   ### How to reproduce
   
   See example source code above.
   
   ### Did this work correctly in an earlier version?
   
   Apache NetBeans 12.3 or earlier
   
   ### Operating System
   
   Windows 10 Enterprise 22H1
   
   ### JDK
   
   Oracle JDK 8u271
   
   ### Apache NetBeans packaging
   
   Apache NetBeans provided installer
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit a pull request?
   
   No
   
   ### Code of Conduct
   
   Yes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to