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/08/27 01:22:02 UTC
[GitHub] [netbeans] blakemcbride opened a new issue, #4545: Incorrect code analysis
blakemcbride opened a new issue, #4545:
URL: https://github.com/apache/netbeans/issues/4545
### Apache NetBeans version
Apache NetBeans 15 release candidate
### What happened
Java variable is being used but NB says it isn't. See two images
![pic1](https://user-images.githubusercontent.com/6467584/187008790-6575256f-c60b-4ac6-a55e-8be4a6608607.png)
![pic2](https://user-images.githubusercontent.com/6467584/187008791-8649967a-c8ee-482e-8326-fe8d33ffa50a.png)
.
### How to reproduce
_No response_
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Fedora Linux
### JDK
8
### 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: 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] mbien commented on issue #4545: Incorrect code analysis
Posted by GitBox <gi...@apache.org>.
mbien commented on issue #4545:
URL: https://github.com/apache/netbeans/issues/4545#issuecomment-1229227791
seems to be specific to final array fields with write ops.
```java
private final static char[] bar1 = {'y', 'n'}; // marked unused
private final static char[] bar2 = new char[2]; // ok
public static void main(String[] args) {
final char[] foo1 = {'y', 'n'}; // marked unused
final char[] foo3 = new char[] {'y', 'n'}; // marked unused
char[] foo2 = {'y', 'n'}; // ok
final char[] foo4 = new char[2]; // ok
char[] foo5; // ok
foo5 = new char[] {'Y', 'n'};
System.out.println(foo1);
System.out.println(foo2);
System.out.println(foo3);
System.out.println(foo4);
System.out.println(foo5);
System.out.println(bar1);
System.out.println(bar2);
}
```
reverting the array handler of #4421 fixes this issue but it would break #4402 again for arrays. Can't come up with a quick way of fixing this atm. Shame we haven't noticed this earlier so we could have simply reverted the PR.
```diff
diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Unbalanced.java b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Unbalanced.java
index 51829b5..3c3d3ae 100644
--- a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Unbalanced.java
+++ b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Unbalanced.java
@@ -152,7 +152,7 @@
if (secondAccess != null) {
record(ctx.getInfo(), var, secondAccess);
}
- } else if (!var.getModifiers().contains(Modifier.FINAL)) {
+ } else {
record(ctx.getInfo(), var, State.WRITE, State.READ);
}
```
--
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] neilcsmith-net commented on issue #4545: Incorrect code analysis
Posted by GitBox <gi...@apache.org>.
neilcsmith-net commented on issue #4545:
URL: https://github.com/apache/netbeans/issues/4545#issuecomment-1231383961
Thanks @mbien I think the whole PR might need reverting - there's a problem with collections as well as arrays. This shows a warning in 15 but not in 14.
```java
public class Test1 {
private final List<String> collection = new ArrayList<>();
public Test1() {
use(collection);
}
public boolean isEmpty() {
return collection.isEmpty();
}
private void use(List<String> list) {
list.add("FOO");
}
}
```
We might need some tests for _not_ containing this warning too? :smile:
--
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] neilcsmith-net commented on issue #4545: Incorrect code analysis
Posted by GitBox <gi...@apache.org>.
neilcsmith-net commented on issue #4545:
URL: https://github.com/apache/netbeans/issues/4545#issuecomment-1229216506
Confirmed. This appears to be a regression caused by #4421 as far as I can tell. cc @mbien can you take a look?
--
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] swpalmer-cl commented on issue #4545: Incorrect code analysis (unbalanced-hint)
Posted by "swpalmer-cl (via GitHub)" <gi...@apache.org>.
swpalmer-cl commented on issue #4545:
URL: https://github.com/apache/netbeans/issues/4545#issuecomment-1680705195
Might be related to this issue:
```
static record Thing(boolean isOkay) {}
void neverRead(Thing thing) {
List<Thing> things = new ArrayList<>(); // NB claims only added to, never read
things.add(thing);
things.forEach(System.out::println); // but here it is read
}
```
--
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