Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NETBEANS-5659] Collection.forEach is always a read from the collection. #6646

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Oct 31, 2023

Having code like:

List<String> l = new ArrayList<>();
l.add("");
l.forEach(e -> {});

will mark the List as unbalanced - only written to, never read. The hint lists the forEach method in the list of read methods, but for (ordinary) read methods, the hint also requires the return value of the read method to be used. forEach is a bit different in this regard, it runs the lambda for the elements, but does not return anything.

This PR introduces a new STANDALONE_READ_METHODS, which do not require their return value to be used.

It also adds the JEP 431: Sequenced Collections from JDK 21 method names.

Filling with NB20 and against delivery, but no strong opinions on this. I am fine with moving this to master/NB21.

@lahodaj lahodaj added the Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) label Oct 31, 2023
@lahodaj lahodaj added this to the NB20 milestone Oct 31, 2023
@lahodaj lahodaj requested review from mbien and dbalek October 31, 2023 16:30
@mbien mbien added the hints label Oct 31, 2023
Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me.

+1 for getting this into NB 20, since a hint like this is independent from everything else and should have low risk of causing side effects.

(edit: although I tried to do this once too for the very same hint and it broke a few things #4580 :), but this change here is simpler)

@neilcsmith-net neilcsmith-net merged commit 43693c8 into apache:delivery Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants