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

   ### Apache NetBeans version
   
   Apache NetBeans 14
   
   ### What happened
   
   Suppose that I've a class with a single field of type `List`. Then, I 
initialize that field in the declaration itself. If I never add any element to 
that collection, NetBeans properly warns me that *The collection is never added 
to*.
   
   However, if I initialize the field in the constructor, NetBeans seems to be 
unable to detect that I still have not added any element to the collection.
   
   
   ### How to reproduce
   
   In this piece of code, NetBeans correctly detects that no element has been 
added to the `collection` field:
   
   ```java
   public final class Test {
   
        private final List<String> collection = new ArrayList<> ();
                              // ^^^ WARNING! The collection is never added to.
   
        public Test () {
        }
   
        public boolean isEmpty () {
                return collection.isEmpty ();
        }
   
   }
   ```
   
   However, if I initialize the field in the constructor, the hint is never 
shown:
   
   ```java
   public final class Test {
   
        private final List<String> collection;
   
        public Test () {
                collection = new ArrayList<> ();
        }
   
        public boolean isEmpty () {
                return collection.isEmpty ();
        }
   
   }
   ```
   
   ### Did this work correctly in an earlier version?
   
   No
   
   ### Operating System
   
   Debian GNU/Linux 11.4 (Bullseye)
   
   ### JDK
   
   OpenJDK Runtime Environment (build 17.0.3+7-Debian-1deb11u1)
   
   ### Apache NetBeans packaging
   
   Apache NetBeans binary zip
   
   ### 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