changeset 56917:b9beeba97204 records-and-sealed

dont allow bodiless records
author vromero
date Mon, 08 Jul 2019 18:54:23 -0400
parents 2392106362e3
children e7455c3923d9
files src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java test/langtools/tools/javac/records/BadRecord.java test/langtools/tools/javac/records/BadRecord.out test/langtools/tools/javac/records/BadUseOfRecordKeywordTest.out test/langtools/tools/javac/records/bodyless_interfaces/AllowBodyLessInterfacesTest.java test/langtools/tools/javac/records/fields/RecordsCantDeclareFieldModifiersTest.java test/langtools/tools/javac/records/fields/RecordsCantDeclareFieldModifiersTest.out test/langtools/tools/javac/records/mandated_members/canonical_constructor/CanonicalConstructorTest.java test/langtools/tools/javac/records/mandated_members/canonical_constructor/MethodParametersForCanonicalConstructorTest.java test/langtools/tools/javac/records/mandated_members/read_resolve_method/CheckReadResolveMethodTest.java test/langtools/tools/javac/records/records_cant_be_abstract/RecordsCantBeAbstractTest.java test/langtools/tools/javac/records/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.java test/langtools/tools/javac/records/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.out test/langtools/tools/javac/records/reflection/RecordReflectionTest.java test/langtools/tools/javac/records/writeread/Record.java
diffstat 15 files changed, 99 insertions(+), 124 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Wed Jul 03 16:16:15 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Jul 08 18:54:23 2019 -0400
@@ -3752,11 +3752,7 @@
             implementing = typeList();
         }
         List<JCTree> defs = List.nil();
-        if (token.kind == LBRACE) {
-            defs = classInterfaceOrRecordBody(name, false, true);
-        } else {
-            accept(SEMI);
-        }
+        defs = classInterfaceOrRecordBody(name, false, true);
         java.util.List<JCVariableDecl> fields = new ArrayList<>();
         Set<Name> seenNames = new HashSet<>();
         for (JCVariableDecl field : headerFields) {
@@ -3863,12 +3859,7 @@
             permitting = typeList();
         }
         List<JCTree> defs;
-        if (token.kind == LBRACE) {
-            defs = classInterfaceOrRecordBody(name, true, false);
-        } else {
-            accept(SEMI);
-            defs = List.nil();
-        }
+        defs = classInterfaceOrRecordBody(name, true, false);
         JCClassDecl result = toP(F.at(pos).ClassDef(
             mods, name, typarams, null, extending, permitting, defs));
         attach(result, dc);
--- a/test/langtools/tools/javac/records/BadRecord.java	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/BadRecord.java	Mon Jul 08 18:54:23 2019 -0400
@@ -3,50 +3,70 @@
  * @summary Verifying error recovery for broken record classes
  * @compile/fail/ref=BadRecord.out -XDrawDiagnostics BadRecord.java
  */
-record BadRecordb1 {}
+record BadRecord001 {}
 
-record BadRecordb2( {}
+record BadRecord0022( {}
 
-record BadRecordb3(int {}
+record BadRecord0033(int {}
 
-record BadRecordb4(int) {}
+record BadRecord0044(int) {}
 
-record BadRecordb5(int i {}
+record BadRecord005(int i {}
 
-record BadRecordb6(int i, {}
+record BadRecord006(int i, {}
 
-record BadRecordb7(int i,) {}
+record BadRecord007(int i,) {}
 
-record BadRecordb8(int i, int {}
+record BadRecord008(int i, int {}
 
-record BadRecordb9(int i, int) {}
+record BadRecord009(int i, int) {}
 
-record BadRecordba(int i, int j {}
+record BadRecord010(int i, int j {}
 
-record BadRecordbb(int i, int j, {}
+record BadRecord011(int i, int j, {}
 
-record BadRecordbc(int i, int j,) {}
+record BadRecord012(int i, int j,) {}
 
-record BadRecords1;
+record BadRecord013;
 
-record BadRecords2(;
+record BadRecord014(;
 
-record BadRecords3(int;
+record BadRecord015(int;
 
-record BadRecords4(int);
+record BadRecord016(int);
 
-record BadRecords5(int i;
+record BadRecord017(int i;
 
-record BadRecords6(int i,;
+record BadRecord018(int i,;
 
-record BadRecords7(int i,);
+record BadRecord019(int i,);
 
-record BadRecords8(int i, int;
+record BadRecord020(int i, int;
 
-record BadRecords9(int i, int);
+record BadRecord021(int i, int);
 
-record BadRecordsa(int i, int j;
+record BadRecord022(int i, int j;
 
-record BadRecordsb(int i, int j,;
+record BadRecord023(int i, int j,;
 
-record BadRecordsc(int i, int j,);
+record BadRecord024(int i, int j,);
+
+record BadRecord025(int x)
+
+record BadRecord026 {}
+
+record BadRecord027(final int x) { }
+
+record BadRecord028(private int x) { }
+
+record BadRecord029(public int x) { }
+
+record BadRecord030(volatile int x) { }
+
+record BadRecord030(int x) {
+    private int x() { return x; }
+}
+
+record R(int x) {
+    public int x;
+}
--- a/test/langtools/tools/javac/records/BadRecord.out	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/BadRecord.out	Mon Jul 08 18:54:23 2019 -0400
@@ -1,25 +1,36 @@
-BadRecord.java:6:19: compiler.err.expected: '('
-BadRecord.java:8:21: compiler.err.illegal.start.of.type
-BadRecord.java:10:23: compiler.err.expected: token.identifier
-BadRecord.java:12:23: compiler.err.expected: token.identifier
-BadRecord.java:14:25: compiler.err.expected: ')'
-BadRecord.java:16:27: compiler.err.illegal.start.of.type
-BadRecord.java:18:26: compiler.err.illegal.start.of.type
-BadRecord.java:20:30: compiler.err.expected: token.identifier
-BadRecord.java:22:30: compiler.err.expected: token.identifier
-BadRecord.java:24:32: compiler.err.expected: ')'
-BadRecord.java:26:34: compiler.err.illegal.start.of.type
-BadRecord.java:28:33: compiler.err.illegal.start.of.type
-BadRecord.java:30:19: compiler.err.expected: '('
-BadRecord.java:32:20: compiler.err.illegal.start.of.type
-BadRecord.java:34:23: compiler.err.expected: token.identifier
-BadRecord.java:36:23: compiler.err.expected: token.identifier
-BadRecord.java:38:25: compiler.err.expected: ')'
-BadRecord.java:40:26: compiler.err.illegal.start.of.type
-BadRecord.java:42:26: compiler.err.illegal.start.of.type
-BadRecord.java:44:30: compiler.err.expected: token.identifier
-BadRecord.java:46:30: compiler.err.expected: token.identifier
-BadRecord.java:48:32: compiler.err.expected: ')'
-BadRecord.java:50:33: compiler.err.illegal.start.of.type
-BadRecord.java:52:33: compiler.err.illegal.start.of.type
-24 errors
+BadRecord.java:6:20: compiler.err.expected: '('
+BadRecord.java:8:23: compiler.err.illegal.start.of.type
+BadRecord.java:10:25: compiler.err.expected: token.identifier
+BadRecord.java:12:25: compiler.err.expected: token.identifier
+BadRecord.java:14:26: compiler.err.expected: ')'
+BadRecord.java:16:28: compiler.err.illegal.start.of.type
+BadRecord.java:18:27: compiler.err.illegal.start.of.type
+BadRecord.java:20:31: compiler.err.expected: token.identifier
+BadRecord.java:22:31: compiler.err.expected: token.identifier
+BadRecord.java:24:33: compiler.err.expected: ')'
+BadRecord.java:26:35: compiler.err.illegal.start.of.type
+BadRecord.java:28:34: compiler.err.illegal.start.of.type
+BadRecord.java:30:20: compiler.err.expected: '('
+BadRecord.java:32:21: compiler.err.illegal.start.of.type
+BadRecord.java:34:24: compiler.err.expected: token.identifier
+BadRecord.java:36:24: compiler.err.expected: token.identifier
+BadRecord.java:36:25: compiler.err.expected: '{'
+BadRecord.java:38:26: compiler.err.expected: ')'
+BadRecord.java:40:27: compiler.err.illegal.start.of.type
+BadRecord.java:42:27: compiler.err.illegal.start.of.type
+BadRecord.java:42:28: compiler.err.expected: '{'
+BadRecord.java:44:31: compiler.err.expected: token.identifier
+BadRecord.java:46:31: compiler.err.expected: token.identifier
+BadRecord.java:46:32: compiler.err.expected: '{'
+BadRecord.java:48:33: compiler.err.expected: ')'
+BadRecord.java:50:34: compiler.err.illegal.start.of.type
+BadRecord.java:52:34: compiler.err.illegal.start.of.type
+BadRecord.java:52:35: compiler.err.expected: '{'
+BadRecord.java:54:27: compiler.err.expected: '{'
+BadRecord.java:58:21: compiler.err.record.cant.declare.field.modifiers
+BadRecord.java:60:21: compiler.err.record.cant.declare.field.modifiers
+BadRecord.java:62:21: compiler.err.record.cant.declare.field.modifiers
+BadRecord.java:64:21: compiler.err.record.cant.declare.field.modifiers
+BadRecord.java:71:16: compiler.err.record.fields.must.be.in.header
+BadRecord.java:72:2: compiler.err.premature.eof
+35 errors
--- a/test/langtools/tools/javac/records/BadUseOfRecordKeywordTest.out	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/BadUseOfRecordKeywordTest.out	Mon Jul 08 18:54:23 2019 -0400
@@ -2,4 +2,6 @@
 BadUseOfRecordKeywordTest.java:13:11: compiler.err.record.not.allowed: record
 BadUseOfRecordKeywordTest.java:15:10: compiler.err.record.not.allowed: record
 BadUseOfRecordKeywordTest.java:17:12: compiler.err.record.not.allowed: record
-4 errors
+BadUseOfRecordKeywordTest.java:17:25: compiler.err.expected: '{'
+BadUseOfRecordKeywordTest.java:18:2: compiler.err.premature.eof
+6 errors
--- a/test/langtools/tools/javac/records/bodyless_interfaces/AllowBodyLessInterfacesTest.java	Wed Jul 03 16:16:15 2019 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2018, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @summary allow for bodyless interfaces
- * @compile AllowBodyLessInterfacesTest.java
- */
-public class AllowBodyLessInterfacesTest {
-    interface Super;
-
-    interface Child extends Super;
-}
--- a/test/langtools/tools/javac/records/fields/RecordsCantDeclareFieldModifiersTest.java	Wed Jul 03 16:16:15 2019 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-/*
- * @test /nodynamiccopyright/
- * @summary smoke negative test for datum classes
- * @compile/fail/ref=RecordsCantDeclareFieldModifiersTest.out -XDrawDiagnostics RecordsCantDeclareFieldModifiersTest.java
- */
-
-public class RecordsCantDeclareFieldModifiersTest {
-    record R(public int i);
-}
--- a/test/langtools/tools/javac/records/fields/RecordsCantDeclareFieldModifiersTest.out	Wed Jul 03 16:16:15 2019 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-RecordsCantDeclareFieldModifiersTest.java:8:14: compiler.err.record.cant.declare.field.modifiers
-1 error
--- a/test/langtools/tools/javac/records/mandated_members/canonical_constructor/CanonicalConstructorTest.java	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/mandated_members/canonical_constructor/CanonicalConstructorTest.java	Mon Jul 08 18:54:23 2019 -0400
@@ -32,7 +32,7 @@
 import com.sun.tools.javac.util.Assert;
 
 public class CanonicalConstructorTest {
-    record R1(int i, int j);
+    record R1(int i, int j) {}
     record R2(int i, int j) {
         public R2 {}
     }
--- a/test/langtools/tools/javac/records/mandated_members/canonical_constructor/MethodParametersForCanonicalConstructorTest.java	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/mandated_members/canonical_constructor/MethodParametersForCanonicalConstructorTest.java	Mon Jul 08 18:54:23 2019 -0400
@@ -36,7 +36,7 @@
 
 public class MethodParametersForCanonicalConstructorTest {
 
-    record R1(int i, int j);
+    record R1(int i, int j) {}
 
     record R2(int i, int j) {
         public R2 {}
--- a/test/langtools/tools/javac/records/mandated_members/read_resolve_method/CheckReadResolveMethodTest.java	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/mandated_members/read_resolve_method/CheckReadResolveMethodTest.java	Mon Jul 08 18:54:23 2019 -0400
@@ -45,10 +45,10 @@
     }
 
     // readResolve should be generated the record implements Serializable
-    record Point2(int i, int j) implements Serializable;
+    record Point2(int i, int j) implements Serializable {}
 
     // no readResolve should be generated as the record doesnt implement Serializable
-    record Point3(int i, int j);
+    record Point3(int i, int j) {}
 
     // no readResolve should be generated as an implementation is already provided
     record Point4(int i, int j) {
--- a/test/langtools/tools/javac/records/records_cant_be_abstract/RecordsCantBeAbstractTest.java	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/records_cant_be_abstract/RecordsCantBeAbstractTest.java	Mon Jul 08 18:54:23 2019 -0400
@@ -4,4 +4,4 @@
  * @compile/fail/ref=RecordsCantBeAbstractTest.out -XDrawDiagnostics RecordsCantBeAbstractTest.java
  */
 
-abstract record RecordsCantBeAbstractTest(int i);
+abstract record RecordsCantBeAbstractTest(int i) {}
--- a/test/langtools/tools/javac/records/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.java	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.java	Mon Jul 08 18:54:23 2019 -0400
@@ -11,10 +11,10 @@
     // even Object which is the implicit super class for records
     record R1(int x) extends Object {}
 
-    record R2(int y);
+    record R2(int y) {}
 
     // can't extend other records either
-    record R3(int y, int x) extends R2(y);
+    record R3(int y, int x) extends R2(y) {}
 
     // records can implement interfaces
     record R4() implements Serializable, Runnable {
--- a/test/langtools/tools/javac/records/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.out	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.out	Mon Jul 08 18:54:23 2019 -0400
@@ -1,6 +1,3 @@
-RecordsCantHaveExtendsClause.java:12:21: compiler.err.expected: ';'
-RecordsCantHaveExtendsClause.java:12:36: compiler.err.expected: token.identifier
-RecordsCantHaveExtendsClause.java:17:28: compiler.err.expected: ';'
-RecordsCantHaveExtendsClause.java:17:37: compiler.err.invalid.meth.decl.ret.type.req
-RecordsCantHaveExtendsClause.java:17:41: compiler.err.expected: token.identifier
-5 errors
+RecordsCantHaveExtendsClause.java:12:21: compiler.err.expected: '{'
+RecordsCantHaveExtendsClause.java:17:28: compiler.err.expected: '{'
+2 errors
--- a/test/langtools/tools/javac/records/reflection/RecordReflectionTest.java	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/reflection/RecordReflectionTest.java	Mon Jul 08 18:54:23 2019 -0400
@@ -37,11 +37,11 @@
 
     class NoRecord {}
 
-    record R1();
+    record R1() {}
 
-    record R2(int i, int j);
+    record R2(int i, int j) {}
 
-    record R3(List<String> ls);
+    record R3(List<String> ls) {}
 
     public static void main(String... args) throws Throwable {
         Class<?> noRecordClass = NoRecord.class;
--- a/test/langtools/tools/javac/records/writeread/Record.java	Wed Jul 03 16:16:15 2019 -0400
+++ b/test/langtools/tools/javac/records/writeread/Record.java	Mon Jul 08 18:54:23 2019 -0400
@@ -25,4 +25,4 @@
 
 import java.util.List;
 
-record Record1<T>(int i, int j, List<String> ls, List<T> lt);
+record Record1<T>(int i, int j, List<String> ls, List<T> lt) {}