Skip to content

Fixes find-usages and call-hierarchy on enum constructors.#8991

Merged
mbien merged 1 commit intoapache:masterfrom
mbien:find-enum-constructor-usage-fix
Nov 11, 2025
Merged

Fixes find-usages and call-hierarchy on enum constructors.#8991
mbien merged 1 commit intoapache:masterfrom
mbien:find-enum-constructor-usage-fix

Conversation

@mbien
Copy link
Member

@mbien mbien commented Nov 6, 2025

Use the fallback codepath if the end position is negative.

unfortunately all tests for the find usage functionality are disabled atm which makes changes in this area a bit risky.

public enum Letters {
    A {
        @Override
        public String toString() {
            return "C";
        }
    }, B;

    Letters() {}
    // ^^ run find usages or call hierarchy
}

to trigger the exception in NB 28, at least one enum field must have a class body {}.

fixes #8985

@mbien mbien added this to the NB29 milestone Nov 6, 2025
@mbien mbien requested a review from lahodaj November 6, 2025 23:19
@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Nov 6, 2025
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

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

I think this is an improvement over the prior state. It might be worth extending the comment in line 208 noting, that the rendering is not perfect (empty label) for these cases, but at least it does not blow.

@mbien
Copy link
Member Author

mbien commented Nov 7, 2025

I tried to track the label problem down yesterday, I might give it another try in case it would only be a UI change. I suspect that it could be, because find-usages does seem to do a better job to find the name of the enum constants than call-hierarchy - while both use the same code path to compute the usages.

@mbien
Copy link
Member Author

mbien commented Nov 7, 2025

i also forgot to mention that i can't access the old bugzilla atm. I asked on slack and it seems like more can't log in. I would also be good to read through the bug IDs which were mentioned in the comments marked as hotfix. I might open a infra issue (edit: INFRA-27390).

@mbien
Copy link
Member Author

mbien commented Nov 11, 2025

i can now view the bugzilla bugs again since my account got repaired, the comment mentions the hotfix for https://bz.apache.org/netbeans/show_bug.cgi?id=213723 which is the exact same bug.
reproducer was:

public enum Tester {
    ENUM1 {
        {
            System.out.println("");
        }
    },
    ENUM2 {
        @Override
        public String toString() {
            return super.toString();
        }
    };
    private Tester() {
    }
}

what I believe happened is that getStartPosition() used to return -1 for enum fields with "class bodies", but at some point it began returning positive start positions, while getStartPosition() still returns -1 to this day. This made the same bug resurface again.

So this PR essentially activates the old hotfix again. cc @jlahoda

Copy link
Contributor

@lahodaj lahodaj left a comment

Choose a reason for hiding this comment

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

Looks sensible. Would be good if we could fix the tests/start to run them at some point.

@mbien mbien force-pushed the find-enum-constructor-usage-fix branch from 770455d to d773653 Compare November 11, 2025 18:41
Use the fallback codepath if the end position is negative.
@mbien mbien removed the ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) label Nov 11, 2025
@mbien mbien force-pushed the find-enum-constructor-usage-fix branch from d773653 to 49d04ad Compare November 11, 2025 18:46
@mbien mbien merged commit 7c4bd1a into apache:master Nov 11, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Find Usages / Call Hierarchy fails with StringIndexOutOfBoundsException on enum constructor

3 participants