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

JAVA_TOOL_OPTIONS=--enable-preview is "picked up" by javac but not used.

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "14-ea" 2020-03-17
      OpenJDK Runtime Environment (build 14-ea+13-480)
      OpenJDK 64-Bit Server VM (build 14-ea+13-480, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      The javac command recognizes JAVA_TOOL_OPTIONS has been "picked up", but it will not apply the --enable-preview .

      Seen in JDK 12, 13, & 14

      REGRESSION : Last worked in version 14

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      set JAVA_TOOL_OPTIONS=--enable-preview
      compile a class that uses previewed features

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      javac to honor the flag it states it "picked up"
      ACTUAL -
      An error that mentions you need to set --enable-preview:

      javac -source 14 Switch.java
      Picked up JAVA_TOOL_OPTIONS: --enable-preview
      Switch.java:6: error: multiple case labels are a preview feature and are disabled by default.
                  case 1, 2 -> System.out.println(3);
                          ^
        (use --enable-preview to enable multiple case labels)
      Switch.java:6: error: switch rules are a preview feature and are disabled by default.
                  case 1, 2 -> System.out.println(3);
                            ^
        (use --enable-preview to enable switch rules)
      2 errors

      ---------- BEGIN SOURCE ----------

      public class Switch {

          public void newSwitch(int i) {
              switch (i) {
                  case 1, 2 -> System.out.println(3);
                  case 3 -> System.out.println(37);
                  default -> System.out.println(100);
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Pass the argument on the command line in addition to (or instead of) via JAVA_TOOL_OPTIONS

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: