You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/10/11 17:13:22 UTC

[GitHub] [netbeans] negora opened a new issue, #4402: "Unbalanced read/write with collections" hint fails for fields initialized in constructor

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

   ### Apache NetBeans version
   
   Apache NetBeans 14
   
   ### What happened
   
   I've a Maven project of type *jar*. Suppose that I also have 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: notifications-unsubscribe@netbeans.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] negora commented on issue #4402: "Unbalanced read/write with collections" hint fails for fields initialized in constructor

Posted by GitBox <gi...@apache.org>.
negora commented on issue #4402:
URL: https://github.com/apache/netbeans/issues/4402#issuecomment-1191962906

   > i can probably fix this for final fields. Non-final would be harder to fix.
   
   Good point. In my opinion, fixing it for final fields would be enough, because it would cover most common situations.
   
   For non-final fields, I think it might be even impossible to achieve in some situations. Because the detection would depend on the order in which the re-assignations occurred. And if the latter were initiated by non-private methods of the current class, then the order would be undefined from the point of view of the class, Right?
   
   Anyway, thank you a lot for fixing it.
   


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] mbien commented on issue #4402: "Unbalanced read/write with collections" hint fails for fields initialized in constructor

Posted by GitBox <gi...@apache.org>.
mbien commented on issue #4402:
URL: https://github.com/apache/netbeans/issues/4402#issuecomment-1192312559

   > > i can probably fix this for final fields. Non-final would be harder to fix.
   > 
   > Good point. In my opinion, fixing it for final fields would be enough, because it would cover most common situations.
   > 
   > For non-final fields, I think it might be even impossible to achieve in some situations. Because the detection would depend on the order in which the re-assignations occurred.
   
   exactly. The way it works is that it records read/write operations in the first pass, the second pass looks at the declaration and prints the hint if its "unbalanced".
   
   an assignment "collection = foo" is marked as read+write and the hint is not shown. However, if we know that the field is final we can simply ignore assignments since we know that its the initial declaration and can't be anything else. The hint doesn't really know in which order things happen as you correctly said.
   
   
   


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] mbien commented on issue #4402: "Unbalanced read/write with collections" hint fails for fields initialized in constructor

Posted by GitBox <gi...@apache.org>.
mbien commented on issue #4402:
URL: https://github.com/apache/netbeans/issues/4402#issuecomment-1275016868

   going to reopen this since we had to revert the hotfix due to it causing more issues.


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] mbien commented on issue #4402: "Unbalanced read/write with collections" hint fails for fields initialized in constructor

Posted by GitBox <gi...@apache.org>.
mbien commented on issue #4402:
URL: https://github.com/apache/netbeans/issues/4402#issuecomment-1191922012

   i can probably fix this for final fields. Non-final would be harder to fix.


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] mbien closed issue #4402: "Unbalanced read/write with collections" hint fails for fields initialized in constructor

Posted by GitBox <gi...@apache.org>.
mbien closed issue #4402: "Unbalanced read/write with collections" hint fails for fields initialized in constructor
URL: https://github.com/apache/netbeans/issues/4402


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] mbien commented on issue #4402: "Unbalanced read/write with collections" hint fails for fields initialized in constructor

Posted by GitBox <gi...@apache.org>.
mbien commented on issue #4402:
URL: https://github.com/apache/netbeans/issues/4402#issuecomment-1197189208

   change made it into 15 rc2 https://lists.apache.org/thread/qw4sd9kqy3c1lftwhl61ftpkcqcd6m0f


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] negora commented on issue #4402: "Unbalanced read/write with collections" hint fails for fields initialized in constructor

Posted by GitBox <gi...@apache.org>.
negora commented on issue #4402:
URL: https://github.com/apache/netbeans/issues/4402#issuecomment-1197720172

   I've quickly tested this in RC2 and it works fine. Thank you!
   


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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