diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index 1a5c9df16c7..6ef45cf58df 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -157,6 +157,9 @@ protected Check(Context context) { enforceMandatoryWarnings, "sunapi", null); deferredLintHandler = DeferredLintHandler.instance(context); + + allowRecords = (!preview.isPreview(Feature.RECORDS) || preview.isEnabled()) && + Feature.RECORDS.allowedInSource(source); } /** Character for synthetic names @@ -188,6 +191,10 @@ protected Check(Context context) { */ private DeferredLintHandler deferredLintHandler; + /** Are records allowed + */ + private final boolean allowRecords; + /* ************************************************************************* * Errors and Warnings **************************************************************************/ @@ -3164,7 +3171,9 @@ private Set getDefaultTargetSet() { targets.add(names.ANNOTATION_TYPE); targets.add(names.CONSTRUCTOR); targets.add(names.FIELD); - targets.add(names.RECORD_COMPONENT); + if (allowRecords) { + targets.add(names.RECORD_COMPONENT); + } targets.add(names.LOCAL_VARIABLE); targets.add(names.METHOD); targets.add(names.PACKAGE); diff --git a/test/langtools/ProblemList.txt b/test/langtools/ProblemList.txt index 975d982b92e..f096990f04b 100644 --- a/test/langtools/ProblemList.txt +++ b/test/langtools/ProblemList.txt @@ -1,6 +1,6 @@ ########################################################################### # -# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2015, 2020, 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 @@ -55,7 +55,6 @@ tools/javac/warnings/suppress/TypeAnnotations.java tools/javac/modules/SourceInSymlinkTest.java 8180263 windows-all fails when run on a subst drive tools/javac/importscope/T8193717.java 8203925 generic-all the test requires too much memory tools/javac/options/BCPOrSystemNotSpecified.java 8231179 windows-all fails when creating a test bootclasspath -tools/javac/annotations/repeatingAnnotations/combo/TargetAnnoCombo.java 8235339 generic-all fails after new annotation target RECORD_COMPONENT was introduced ########################################################################### # diff --git a/test/langtools/tools/javac/annotations/repeatingAnnotations/combo/Helper.java b/test/langtools/tools/javac/annotations/repeatingAnnotations/combo/Helper.java index 642f434b606..a8167846c0a 100644 --- a/test/langtools/tools/javac/annotations/repeatingAnnotations/combo/Helper.java +++ b/test/langtools/tools/javac/annotations/repeatingAnnotations/combo/Helper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2020, 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 @@ -96,6 +96,10 @@ public static boolean compileCode(String className, String contents, static File destDir = new File(System.getProperty("user.dir")); public static boolean compileCode(DiagnosticCollector diagnostics, Iterable files) { + return compileCode(diagnostics, files, null); + } + + public static boolean compileCode(DiagnosticCollector diagnostics, Iterable files, Iterable options) { boolean ok = false; JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); if (compiler == null) { @@ -105,7 +109,7 @@ public static boolean compileCode(DiagnosticCollector diagnostic try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { // Assuming filesCount can maximum be 2 and if true, one file is package-info.java if (isPkgInfoPresent(files)) { - JavacTask task = (JavacTask) compiler.getTask(null, fm, diagnostics, null, null, files); + JavacTask task = (JavacTask) compiler.getTask(null, fm, diagnostics, options, null, files); try { fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir)); task.generate(); @@ -120,7 +124,7 @@ public static boolean compileCode(DiagnosticCollector diagnostic } ok = (err == 0); } else { - CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, files); + CompilationTask task = compiler.getTask(null, null, diagnostics, options, null, files); ok = task.call(); } return ok; diff --git a/test/langtools/tools/javac/annotations/repeatingAnnotations/combo/TargetAnnoCombo.java b/test/langtools/tools/javac/annotations/repeatingAnnotations/combo/TargetAnnoCombo.java index 982c9abbefe..b22b3d10638 100644 --- a/test/langtools/tools/javac/annotations/repeatingAnnotations/combo/TargetAnnoCombo.java +++ b/test/langtools/tools/javac/annotations/repeatingAnnotations/combo/TargetAnnoCombo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2020, 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 @@ -66,7 +66,7 @@ public class TargetAnnoCombo { final static Set empty = EnumSet.noneOf(ElementType.class); // [TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, - // PACKAGE, TYPE_PARAMETER, TYPE_USE] + // PACKAGE, TYPE_PARAMETER, TYPE_USE, RECORD_COMPONENT] final static Set allTargets = EnumSet.allOf(ElementType.class); // [TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, @@ -93,16 +93,22 @@ private class TestCase { private Set baseAnnotations; private Set containerAnnotations; private IgnoreKind ignore; + java.util.List options; public TestCase(Set baseAnnotations, Set containerAnnotations) { - this(baseAnnotations, containerAnnotations, IgnoreKind.RUN); + this(baseAnnotations, containerAnnotations, IgnoreKind.RUN, null); + } + + public TestCase(Set baseAnnotations, Set containerAnnotations, List options) { + this(baseAnnotations, containerAnnotations, IgnoreKind.RUN, options); } public TestCase(Set baseAnnotations, Set containerAnnotations, - IgnoreKind ignoreKind) { + IgnoreKind ignoreKind, java.util.List options) { this.baseAnnotations = baseAnnotations; this.containerAnnotations = containerAnnotations; this.ignore = ignoreKind; + this.options = options; } public Set getBaseAnnotations() { @@ -198,6 +204,12 @@ public static void main(String args[]) throws Exception { } } + // options to be passed if all targets, including RECORD_COMPONENTS, are to be considered + List previewOptions = List.of( + "--enable-preview", + "-source", Integer.toString(Runtime.version().feature()) + ); + private void generate() { // Adding test cases to run. testCases.addAll(Arrays.asList( @@ -257,7 +269,7 @@ private void generate() { // No container against jdk7 targets plus one or both of TYPE_USE, TYPE_PARAMETER new TestCase(plus(jdk7, TYPE_USE), noSet), new TestCase(plus(jdk7, TYPE_PARAMETER), noSet), - new TestCase(allTargets, noSet), + new TestCase(allTargets, noSet, previewOptions), // Empty container target against any lone target. new TestCase(plus(empty, TYPE), empty), new TestCase(plus(empty, PARAMETER), empty), @@ -270,34 +282,34 @@ private void generate() { new TestCase(plus(empty, TYPE_USE), empty), new TestCase(plus(empty, TYPE_PARAMETER), empty), // All base targets against all container targets. - new TestCase(allTargets, allTargets), + new TestCase(allTargets, allTargets, previewOptions), // All base targets against all but one container targets. - new TestCase(allTargets, less(allTargets, TYPE)), - new TestCase(allTargets, less(allTargets, PARAMETER)), - new TestCase(allTargets, less(allTargets, PACKAGE)), - new TestCase(allTargets, less(allTargets, METHOD)), - new TestCase(allTargets, less(allTargets, LOCAL_VARIABLE)), - new TestCase(allTargets, less(allTargets, FIELD)), - new TestCase(allTargets, less(allTargets, CONSTRUCTOR)), - new TestCase(allTargets, less(allTargets, ANNOTATION_TYPE)), - new TestCase(allTargets, less(allTargets, TYPE_USE)), - new TestCase(allTargets, less(allTargets, TYPE_PARAMETER)), + new TestCase(allTargets, less(allTargets, TYPE), previewOptions), + new TestCase(allTargets, less(allTargets, PARAMETER), previewOptions), + new TestCase(allTargets, less(allTargets, PACKAGE), previewOptions), + new TestCase(allTargets, less(allTargets, METHOD), previewOptions), + new TestCase(allTargets, less(allTargets, LOCAL_VARIABLE), previewOptions), + new TestCase(allTargets, less(allTargets, FIELD), previewOptions), + new TestCase(allTargets, less(allTargets, CONSTRUCTOR), previewOptions), + new TestCase(allTargets, less(allTargets, ANNOTATION_TYPE), previewOptions), + new TestCase(allTargets, less(allTargets, TYPE_USE), previewOptions), + new TestCase(allTargets, less(allTargets, TYPE_PARAMETER), previewOptions), // All container targets against all but one base targets. - new TestCase(less(allTargets, TYPE), allTargets), - new TestCase(less(allTargets, PARAMETER), allTargets), - new TestCase(less(allTargets, PACKAGE), allTargets), - new TestCase(less(allTargets, METHOD), allTargets), - new TestCase(less(allTargets, LOCAL_VARIABLE), allTargets), - new TestCase(less(allTargets, FIELD), allTargets), - new TestCase(less(allTargets, CONSTRUCTOR), allTargets), - new TestCase(less(allTargets, ANNOTATION_TYPE), allTargets), - new TestCase(less(allTargets, TYPE_USE), allTargets), - new TestCase(less(allTargets, TYPE_PARAMETER), allTargets))); + new TestCase(less(allTargets, TYPE), allTargets, previewOptions), + new TestCase(less(allTargets, PARAMETER), allTargets, previewOptions), + new TestCase(less(allTargets, PACKAGE), allTargets, previewOptions), + new TestCase(less(allTargets, METHOD), allTargets, previewOptions), + new TestCase(less(allTargets, LOCAL_VARIABLE), allTargets, previewOptions), + new TestCase(less(allTargets, FIELD), allTargets, previewOptions), + new TestCase(less(allTargets, CONSTRUCTOR), allTargets, previewOptions), + new TestCase(less(allTargets, ANNOTATION_TYPE), allTargets, previewOptions), + new TestCase(less(allTargets, TYPE_USE), allTargets, previewOptions), + new TestCase(less(allTargets, TYPE_PARAMETER), allTargets, previewOptions))); // Generates 100 test cases for any lone base target contained in Set // allTargets against any lone container target. for (ElementType b : allTargets) { for (ElementType c : allTargets) { - testCases.add(new TestCase(plus(empty, b), plus(empty, c))); + testCases.add(new TestCase(plus(empty, b), plus(empty, c), previewOptions)); } } } @@ -325,7 +337,7 @@ private void executeTestCase(TestCase testCase, int index) { boolean shouldCompile = testCase.isValidSubSet(); Iterable files = getFileList(className, testCase, shouldCompile); // Get result of compiling test src file(s). - boolean result = getCompileResult(className, shouldCompile, files); + boolean result = getCompileResult(className, shouldCompile, files, testCase.options); // List test src code if test fails. if (!result) { System.out.println("FAIL: Test " + index); @@ -420,11 +432,11 @@ private Iterable getFileList(String className, // Compile the test source file(s) and return test result. private boolean getCompileResult(String className, boolean shouldCompile, - Iterable files) { + Iterable files, Iterable options) { DiagnosticCollector diagnostics = new DiagnosticCollector(); - Helper.compileCode(diagnostics, files); + Helper.compileCode(diagnostics, files, options); // Test case pass or fail. boolean ok = false; String errMesg = ""; @@ -440,8 +452,13 @@ private boolean getCompileResult(String className, boolean shouldCompile, } else { if (shouldCompile) { // did not compile. - errMesg = "Test failed, did not compile."; - ok = false; + List> allDiagnostics = diagnostics.getDiagnostics(); + if (allDiagnostics.stream().noneMatch(d -> d.getKind() == javax.tools.Diagnostic.Kind.ERROR)) { + ok = true; + } else { + errMesg = "Test failed, compiled unexpectedly."; + ok = false; + } } else { // Error in compilation as expected. String expectedErrKey = "compiler.err.invalid.repeatable."