nmatt opened a new issue, #9198:
URL: https://github.com/apache/netbeans/issues/9198
### Apache NetBeans version
Apache NetBeans 28
### What happened
In an enhanced `for` loop with an empty body (or an otherwise seemingly
unused loop variable), the hint 'Remove unused "_variable_"' is offered. When
selecting the hint, an Unexpected Exception occurs:
`java.lang.ClassCastException: class com.sun.tools.javac.tree.JCTree$JCBlock
cannot be cast to class com.sun.source.tree.VariableTree`.
While selecting the hint obvisously doesn't make much sense, it can happen
by accident when selecting another hint on the `for` loop was intended, for
example 'Change type of _variable_ to _correct type_' when the loop variable
type doesn't match the iterable expression type. Not offering the nonsensical
"Remove unused variable" hint in the first place would help prevent selecting
the wrong hint.
### Language / Project Type / NetBeans Component
Java, Hints
### How to reproduce
With the following code in Java statement context:
```java
for (int key : System.getenv().keySet()) { }
```
Both 'Remove unused "key"' and 'Change type of key to String' are offered.
Selecting the former causes the Unexpected Exception.
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Windows
### JDK
17
### Apache NetBeans packaging
Apache NetBeans binary zip
### Anything else
_No response_
### Are you willing to submit a pull request?
No
--
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