Skip to content

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

@errael

Description

@errael

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.

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 #202511241048176470475122.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)hintskind:bugBug report or fix

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions