Skip to content

Conversation

@mbien
Copy link
Member

@mbien mbien commented Sep 22, 2025

Some hints didn't (correctly) check if the feature was supported by the source version / preview flag combination.

example:

NB 27 will suggest to convert this into a rule switch on JDK 17 (without preview enabled) which it shouldn't:

    public static void foo(Object obj) {
        if (obj instanceof Integer i) {
            System.out.println(i);
        } else if (obj instanceof Long l) {
            System.out.println(l);
        }
    }

(feature went final in 21)

@mbien mbien added this to the NB28 milestone Sep 22, 2025
@mbien mbien requested a review from lahodaj September 22, 2025 01:03
@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) hints labels Sep 22, 2025
@mbien
Copy link
Member Author

mbien commented Sep 22, 2025

will take another look today and make this a bit nicer. Planning to move the lang feature check into an enum, since the catch-all utility class is already large enough.

edit: done

@mbien mbien force-pushed the hints-missing-preview-feature-checks branch 2 times, most recently from 7c30487 to 7e2af35 Compare September 22, 2025 16:12
@mbien
Copy link
Member Author

mbien commented Sep 22, 2025

I hoped I could use the enum from within the annotation, but I forgot that enum fields don't count as constants from javac's POV, since they are created during construction.

e.g this doesn't work:

@Hint(displayName = "#DN_ConvertToTextBlock", description = "#DESC_ConvertToTextBlock", category="rules15",
      minSourceVersion = Feature.TEXT_BLOCK.PREVIEW)

Copy link
Contributor

@lkishalmi lkishalmi left a comment

Choose a reason for hiding this comment

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

Nice!

Some hints didn't check if the feature was supported by the source
version / preview flag combination.
@mbien mbien force-pushed the hints-missing-preview-feature-checks branch from 7e2af35 to 0b13dfc Compare October 2, 2025 18:25
@mbien mbien merged commit 6befb30 into apache:master Oct 2, 2025
35 checks passed
@lahodaj
Copy link
Contributor

lahodaj commented Oct 2, 2025

FWIW, makes sense to me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hints 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.

3 participants