Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8304671

javac regression: Compilation with --release 8 fails on underscore in enum identifiers

    XMLWordPrintable

Details

    • b10
    • 14
    • b16
    • generic
    • generic

    Backports

      Description

        Using the underscore '_' as identifier was forbidden with JDK 9, however still allowed for JDK8. Hence the attached example coding should compile with the javac option '--release 8'.

        This fails to work with JDK14 (and newer):
        --------------
        OpenJDK\14\bin\javac --release 8 UnderscoreEnum.java
        UnderscoreEnum.java:4: error: enum constant expected here
                NULL(null), _("&&"), __("||"), OR("OR");
                            ^
        UnderscoreEnum.java:4: warning: as of release 9, '_' is a keyword, and may not be used as an identifier
                NULL(null), _("&&"), __("||"), OR("OR");
                            ^
        UnderscoreEnum.java:4: error: illegal start of type
                NULL(null), _("&&"), __("||"), OR("OR");
                              ^
        UnderscoreEnum.java:9: error: illegal start of expression
                CCEnum(final String value) {
                       ^
        UnderscoreEnum.java:9: error: ';' expected
                CCEnum(final String value) {
                                         ^
        4 errors
        1 warning

        With JDK13 or below, it still works nicely:
        --------------
        OpenJDK\13\bin\javac.exe --release 8 UnderscoreEnum.java
        UnderscoreEnum.java:4: warning: as of release 9, '_' is a keyword, and may not be used as an identifier
                NULL(null), _("&&"), __("||"), OR("OR");
                            ^
        1 warning

        Simple identifiers named '_' work with --release 8 (or -source 8); but when used in enum the compatibility breaks.

        Attachments

          Issue Links

            Activity

              People

                jlahoda Jan Lahoda
                mbaesken Matthias Baesken
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: