apache / apache/netbeans

invalide java editor warn/hint: the assigned value is never used

Open
#9,399 0 comments 0 reactions 0 assignees View on GitHub
hints Java kind:bug
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 30

### What happened

Editing java file, get `the assigned value is never used`. This is not accurate, should be no warning.

### Language / Project Type / NetBeans Component

_No response_

### How to reproduce

1. Edit the following `class Warn`

Observe the warning on the indicated line: `data = switch(o) {`

Note: it looks like the analysis is getting confused by the `throw`. Replace the throw, like with `"j"`, and the warning goes away.

```java
package com.raelity.play.warn;

public class Warn {
public void f()
{
String data = null;
Object o = g(null);
if (o != null) {
data = switch(o) { // warn: the assigned value is never used
case Integer _ -> "i";
default -> throw new IllegalArgumentException();
};
}
g(data);
}
Object g(Object o) {
return 1;
}
}
```

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Linux harmony 6.17.9-76061709-generic #202511241048~1764704751~22.04~b24b425 SMP PREEMPT_DYNAMIC Tue D x86_64 x86_64 x86_64 GNU/Linux

### JDK

openjdk version "26" 2026-03-17 OpenJDK Runtime Environment (build 26+35-2893) OpenJDK 64-Bit Server VM (build 26+35-2893, mixed mode, sharing)

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

_No response_

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Reproduce the warning in the NetBeans Java editor using the `Warn` class and the `data = switch(o)` line in method `f`. Compare the diagnostic when the switch default arm throws with the version returning a string, then verify that the false “assigned value is never used” warning disappears without changing the program behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.