< prev index next >

test/langtools/tools/javac/preview/PreviewAutoSuppress.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 42,10 ***
--- 42,12 ---
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.util.List;
  
  public class PreviewAutoSuppress extends TestRunner {
+     // Major version number (e.g. '27').
+     private static final String FEATURE_VERSION = String.valueOf(Runtime.version().feature());
  
      protected ToolBox tb;
  
      PreviewAutoSuppress() {
          super(System.err);

*** 81,23 ***
          Path classes = base.resolve("classes");
  
          List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
                  .outdir(classes)
                  .options("--enable-preview",
!                          "-source", String.valueOf(Runtime.version().feature()),
                           "-Xlint:preview",
                           "-XDforcePreview",
                           "-XDrawDiagnostics")
                  .files(tb.findJavaFiles(src))
                  .run()
                  .writeAll()
                  .getOutputLines(Task.OutputKind.DIRECT);
  
          List<String> expected =
!                 List.of("Outer.java:3:5: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.records)",
                          "Outer.java:3:5: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.records)",
!                         "2 warnings");
          if (!log.equals(expected))
              throw new Exception("expected output not found" + log);
          checkPreviewClassfile(classes.resolve("test").resolve("Outer.class"), true); //TODO: correct?
          checkPreviewClassfile(classes.resolve("test").resolve("Outer$R.class"),true);
          checkPreviewClassfile(classes.resolve("test").resolve("Use.class"),false);
--- 83,25 ---
          Path classes = base.resolve("classes");
  
          List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
                  .outdir(classes)
                  .options("--enable-preview",
!                          "-source", FEATURE_VERSION,
                           "-Xlint:preview",
                           "-XDforcePreview",
                           "-XDrawDiagnostics")
                  .files(tb.findJavaFiles(src))
                  .run()
                  .writeAll()
                  .getOutputLines(Task.OutputKind.DIRECT);
  
+         // As of Valhalla, j.l.Record is a preview class
          List<String> expected =
!                 List.of("- compiler.warn.preview.feature.use.classfile: Record.class, " + FEATURE_VERSION,
                          "Outer.java:3:5: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.records)",
!                         "Outer.java:3:5: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.records)",
+                         "3 warnings");
          if (!log.equals(expected))
              throw new Exception("expected output not found" + log);
          checkPreviewClassfile(classes.resolve("test").resolve("Outer.class"), true); //TODO: correct?
          checkPreviewClassfile(classes.resolve("test").resolve("Outer$R.class"),true);
          checkPreviewClassfile(classes.resolve("test").resolve("Use.class"),false);

*** 180,11 ***
                  .outdir(testClasses)
                  .options("--patch-module", "java.base=" + apiClasses.toString(),
                           "--add-exports", "java.base/preview.api=ALL-UNNAMED",
                           "--enable-preview",
                           "-Xlint:preview",
!                          "-source", String.valueOf(Runtime.version().feature()),
                           "-XDrawDiagnostics")
                  .files(tb.findJavaFiles(testSrc))
                  .run()
                  .writeAll()
                  .getOutputLines(Task.OutputKind.DIRECT);
--- 184,11 ---
                  .outdir(testClasses)
                  .options("--patch-module", "java.base=" + apiClasses.toString(),
                           "--add-exports", "java.base/preview.api=ALL-UNNAMED",
                           "--enable-preview",
                           "-Xlint:preview",
!                          "-source", FEATURE_VERSION,
                           "-XDrawDiagnostics")
                  .files(tb.findJavaFiles(testSrc))
                  .run()
                  .writeAll()
                  .getOutputLines(Task.OutputKind.DIRECT);
< prev index next >