OpenJDK / amber / amber
changeset 56803:613a80e8256f amber-demo-II
Automatic merge with records-and-sealed
author | mcimadamore |
---|---|
date | Tue, 18 Jun 2019 21:30:24 +0200 |
parents | ac070cb22818 a7ed37b357b7 |
children | fa374e622161 |
files | test/langtools/tools/javac/datum/BadRecord.java test/langtools/tools/javac/datum/BadRecord.out test/langtools/tools/javac/datum/BadUseOfRecordTest.java test/langtools/tools/javac/datum/BadUseOfRecordTest.out test/langtools/tools/javac/datum/CheckDatumMembersAccess.java test/langtools/tools/javac/datum/CheckReadResolveMethodTest.java test/langtools/tools/javac/datum/DataClassTest.java test/langtools/tools/javac/datum/DatumCanNotDeclaredFieldsWithSameName.java test/langtools/tools/javac/datum/DatumCanNotDeclaredFieldsWithSameName.out test/langtools/tools/javac/datum/Neg01.java test/langtools/tools/javac/datum/Neg01.out test/langtools/tools/javac/datum/NoAddFieldsCanBeDeclaredInDatumTest.java test/langtools/tools/javac/datum/NoAddFieldsCanBeDeclaredInDatumTest.out test/langtools/tools/javac/datum/ParameterLessConstructorsTest.java test/langtools/tools/javac/datum/Pos01.java test/langtools/tools/javac/datum/RecordsCanReDeclareMembersTest.java test/langtools/tools/javac/datum/RecordsCantDeclareFieldModifiersTest.java test/langtools/tools/javac/datum/RecordsCantDeclareFieldModifiersTest.out test/langtools/tools/javac/datum/UserDefinedAccessorsMustBePublic.java test/langtools/tools/javac/datum/UserDefinedAccessorsMustBePublic.out test/langtools/tools/javac/datum/UserDefinedMethodsTest.java test/langtools/tools/javac/datum/allow_static_fields/AllowStaticFieldsInRecordsTest.java test/langtools/tools/javac/datum/bodyless_interfaces/AllowBodyLessInterfacesTest.java test/langtools/tools/javac/datum/canonical_constructor/BadCanonicalConstructorTest.java test/langtools/tools/javac/datum/canonical_constructor/BadCanonicalConstructorTest.out test/langtools/tools/javac/datum/canonical_constructor/CanonicalConstructorTest.java test/langtools/tools/javac/datum/fields/RecordFieldsTest.java test/langtools/tools/javac/datum/nested_records_must_be_static_and_final/NestedRecordsMustBeStaticAndFinalTest.java test/langtools/tools/javac/datum/records_cant_be_abstract/RecordsCantBeAbstractTest.java test/langtools/tools/javac/datum/records_cant_be_abstract/RecordsCantBeAbstractTest.out test/langtools/tools/javac/datum/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.java test/langtools/tools/javac/datum/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.out test/langtools/tools/javac/datum/writeread/Record.java test/langtools/tools/javac/datum/writeread/WriteReadTest.java |
diffstat | 65 files changed, 1112 insertions(+), 1182 deletions(-) [+] |
line wrap: on
line diff
--- a/test/langtools/tools/javac/datum/BadRecord.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @summary Verifying error recovery for broken record classes - * @compile/fail/ref=BadRecord.out -XDrawDiagnostics BadRecord.java - */ -record BadRecordb1 {} - -record BadRecordb2( {} - -record BadRecordb3(int {} - -record BadRecordb4(int) {} - -record BadRecordb5(int i {} - -record BadRecordb6(int i, {} - -record BadRecordb7(int i,) {} - -record BadRecordb8(int i, int {} - -record BadRecordb9(int i, int) {} - -record BadRecordba(int i, int j {} - -record BadRecordbb(int i, int j, {} - -record BadRecordbc(int i, int j,) {} - -record BadRecords1; - -record BadRecords2(; - -record BadRecords3(int; - -record BadRecords4(int); - -record BadRecords5(int i; - -record BadRecords6(int i,; - -record BadRecords7(int i,); - -record BadRecords8(int i, int; - -record BadRecords9(int i, int); - -record BadRecordsa(int i, int j; - -record BadRecordsb(int i, int j,; - -record BadRecordsc(int i, int j,);
--- a/test/langtools/tools/javac/datum/BadRecord.out Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -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
--- a/test/langtools/tools/javac/datum/BadUseOfRecordTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @summary check that record is not used as a type name - * @compile/fail/ref=BadUseOfRecordTest.out -XDrawDiagnostics BadUseOfRecordTest.java - */ - -class BadUseOfRecordTest { - - interface record { - void m(); - } - - class record {} - - enum record {A, B} - - record record(int x); -}
--- a/test/langtools/tools/javac/datum/BadUseOfRecordTest.out Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -BadUseOfRecordTest.java:9:15: compiler.err.record.not.allowed: record -BadUseOfRecordTest.java:13:11: compiler.err.record.not.allowed: record -BadUseOfRecordTest.java:15:10: compiler.err.record.not.allowed: record -BadUseOfRecordTest.java:17:12: compiler.err.record.not.allowed: record -4 errors
--- a/test/langtools/tools/javac/datum/CheckDatumMembersAccess.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2017, 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. - * - * 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 check that members of abtract datum has protected access - * @modules jdk.jdeps/com.sun.tools.classfile - * jdk.compiler/com.sun.tools.javac.util - * @compile CheckDatumMembersAccess.java - * @run main CheckDatumMembersAccess - */ - -import com.sun.tools.classfile.ClassFile; - -import java.io.File; - -import com.sun.tools.classfile.AccessFlags; -import com.sun.tools.classfile.Field; -import com.sun.tools.classfile.Method; -import com.sun.tools.javac.util.Assert; - -public class CheckDatumMembersAccess { - - record Datum(int field) {} - - public static void main(String args[]) throws Throwable { - new CheckDatumMembersAccess().run(); - } - - void run() throws Throwable { - checkNonAbstractDatum(); - } - - void checkNonAbstractDatum() throws Throwable { - File testClasses = new File(System.getProperty("test.classes")); - File file = new File(testClasses, - CheckDatumMembersAccess.class.getName() + "$Datum.class"); - ClassFile classFile = ClassFile.read(file); - for (Field f : classFile.fields) { - if (f.getName(classFile.constant_pool).equals("field")) { - Assert.check((f.access_flags.flags & (AccessFlags.ACC_FINAL | AccessFlags.ACC_PRIVATE)) != 0, "record fields should be final and private"); - } - } - } -}
--- a/test/langtools/tools/javac/datum/CheckReadResolveMethodTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +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. - * - * 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 check that members of abtract datum has protected access - * @modules jdk.jdeps/com.sun.tools.classfile - * jdk.compiler/com.sun.tools.javac.util - * @compile CheckReadResolveMethodTest.java - * @run main CheckReadResolveMethodTest - */ - -import java.io.*; - -import com.sun.tools.classfile.*; - -public class CheckReadResolveMethodTest { - - // readResolve should be generated as a constructor is provided - record Point1(int i, int j) implements Serializable { - Point1(int i, int j) { - this.i = i; - this.j = j; - } - } - - // readResolve should be generated the record 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); - - // no readResolve should be generated as an implementation is already provided - record Point4(int i, int j) { - private Object readResolve() { - return new Point4(i, j); - } - } - - // no readResolve should be generated as an implementation of readObject is already provided - record Point5(int i, int j) { - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {} - } - - public static void main(String args[]) throws Throwable { - new CheckReadResolveMethodTest().run(); - } - - void run() throws Throwable { - checkReadResolveMethod("Point1", true); - checkReadResolveMethod("Point2", true); - checkReadResolveMethod("Point3", false); - checkReadResolveMethod("Point4", true); - checkReadResolveMethod("Point5", false); - } - - void checkReadResolveMethod(String className, boolean shouldBeThere) throws Throwable { - File testClasses = new File(System.getProperty("test.classes")); - File file = new File(testClasses, - CheckReadResolveMethodTest.class.getName() + "$" + className +".class"); - ClassFile classFile = ClassFile.read(file); - boolean found = false; - for (Method f : classFile.methods) { - if (f.getName(classFile.constant_pool).equals("readResolve")) { - found = true; - } - } - if (found != shouldBeThere) { - throw new AssertionError("incorrect generation of readResolve method at class " + className); - } - } -}
--- a/test/langtools/tools/javac/datum/DataClassTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2017, 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. - */ - -/** - * DataClassTest - * - * @test - * @library /tools/javac/lib - * @modules jdk.compiler/com.sun.tools.javac.file - * jdk.compiler/com.sun.tools.javac.api - * jdk.compiler/com.sun.tools.javac.util - * @build combo.ComboTestHelper - - * @run main DataClassTest - */ - -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import javax.tools.JavaFileObject; - -import com.sun.tools.javac.file.PathFileObject; -import combo.ComboTask; - -public class DataClassTest extends combo.ComboInstance<DataClassTest> { - - enum FieldTypeKind implements combo.ComboParameter { - BYTE("byte", byte.class), - SHORT("short", short.class), - CHAR("char", char.class), - INT("int", int.class), - LONG("long", long.class), - FLOAT("float", float.class), - DOUBLE("double", double.class), - BOOLEAN("boolean", boolean.class), - OBJECT("Object", Object.class), - STRING("String", String.class); - - String retTypeStr; - Class<?> clazz; - - FieldTypeKind(String retTypeStr, Class<?> clazz) { - this.retTypeStr = retTypeStr; - this.clazz = clazz; - } - - public String expand(String optParameter) { - return retTypeStr; - } - } - - static final Map<FieldTypeKind, List<Object>> dataValues - = Map.ofEntries( - Map.entry(FieldTypeKind.BYTE, List.of(Byte.MIN_VALUE, (byte) -4, (byte) -1, (byte) 0, (byte) 1, (byte) 4, Byte.MAX_VALUE)), - Map.entry(FieldTypeKind.SHORT, List.of(Short.MIN_VALUE, (short) -4, (short) -1, (short) 0, (short) 1, (short) 4, Short.MAX_VALUE)), - Map.entry(FieldTypeKind.CHAR, List.of(Character.MIN_VALUE, 'a', 'A', 'z', (char) 0, Character.MAX_VALUE)), - Map.entry(FieldTypeKind.INT, List.of(Integer.MIN_VALUE, (int) -4, (int) -1, (int) 0, (int) 1, (int) 4, Integer.MAX_VALUE)), - Map.entry(FieldTypeKind.LONG, List.of(Long.MIN_VALUE, (long) -4, (long) -1, (long) 0, (long) 1, (long) 4, Long.MAX_VALUE)), - Map.entry(FieldTypeKind.FLOAT, List.of(Float.MIN_VALUE, Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f, -0.0f, 1.0f, -1.0f, 2.0f, -2.0f, Float.MAX_VALUE)), - Map.entry(FieldTypeKind.DOUBLE, List.of(Double.MIN_VALUE, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0.0d, -0.0d, 1.0d, -1.0d, 2.0d, -2.0d, Double.MAX_VALUE)), - Map.entry(FieldTypeKind.BOOLEAN, List.of(true, false)), - Map.entry(FieldTypeKind.OBJECT, Arrays.asList(null, 3, "foo", new String[] {"a"})), - Map.entry(FieldTypeKind.STRING, Arrays.asList(null, "", "foo", "bar")) - ); - - static final String sourceTemplate = - "record Data(#{FT[0]} f0, #{FT[1]} f1) { }"; - - public static void main(String... args) throws Exception { - new combo.ComboTestHelper<DataClassTest>() - .withArrayDimension("FT", (x, t, index) -> { - x.fieldType[index] = t; - }, 2, FieldTypeKind.values()) - .run(DataClassTest::new); - } - - FieldTypeKind[] fieldType = new FieldTypeKind[2]; - - @Override - public void doWork() throws Throwable { - newCompilationTask() - .withSourceFromTemplate(sourceTemplate) - .generate(this::check); - } - - void check(ComboTask.Result<Iterable<? extends JavaFileObject>> result) { - List<Object> f0s = dataValues.get(fieldType[0]); - List<Object> f1s = dataValues.get(fieldType[1]); - - if (result.hasErrors() || result.hasWarnings()) - fail("Compilation errors not expected: " + result.compilationInfo()); - - Iterable<? extends PathFileObject> pfoIt = (Iterable<? extends PathFileObject>) result.get(); - PathFileObject pfo = pfoIt.iterator().next(); - Class<?> clazz; - Constructor<?> ctor; - Method getterF0, getterF1, hashCodeMethod, equalsMethod, toStringMethod; - Field fieldF0, fieldF1; - - try { - URL[] urls = new URL[] {pfo.getPath().getParent().toUri().toURL()}; - ClassLoader cl = new URLClassLoader(urls); - clazz = cl.loadClass("Data"); - - ctor = clazz.getConstructor(fieldType[0].clazz, fieldType[1].clazz); - getterF0 = clazz.getMethod("f0"); - getterF1 = clazz.getMethod("f1"); - fieldF0 = clazz.getDeclaredField("f0"); - fieldF1 = clazz.getDeclaredField("f1"); - equalsMethod = clazz.getMethod("equals", Object.class); - hashCodeMethod = clazz.getMethod("hashCode"); - toStringMethod = clazz.getMethod("toString"); - - if (getterF0.getReturnType() != fieldType[0].clazz - || getterF1.getReturnType() != fieldType[1].clazz - || fieldF0.getType() != fieldType[0].clazz - || fieldF1.getType() != fieldType[1].clazz) - fail("Unexpected field or getter type: " + result.compilationInfo()); - - for (AccessibleObject o : List.of(ctor, getterF0, getterF1, equalsMethod, hashCodeMethod, toStringMethod)) { - // @@@ Why do we need this? - o.setAccessible(true); - } - - for (Object f0 : f0s) { - for (Object f1 : f1s) { - // Create object - Object datum = ctor.newInstance(f0, f1); - - // Test getters - Object actualF0 = getterF0.invoke(datum); - Object actualF1 = getterF1.invoke(datum); - if (!Objects.equals(f0, actualF0) || !Objects.equals(f1, actualF1)) - fail(String.format("Getters don't report back right values for %s %s/%s, %s %s/%s", - fieldType[0].clazz, f0, actualF0, - fieldType[1].clazz, f1, actualF1)); - - int hashCode = (int) hashCodeMethod.invoke(datum); - int expectedHash = Objects.hash(f0, f1); - // @@@ fail - if (hashCode != expectedHash) { - System.err.println(String.format("Hashcode not as expected: expected=%d, actual=%d", - expectedHash, hashCode)); - } - - String toString = (String) toStringMethod.invoke(datum); - String expectedToString = String.format("Data[f0=%s, f1=%s]", f0, f1); - if (!toString.equals(expectedToString)) { - fail(String.format("ToString not as expected: expected=%s, actual=%s", - expectedToString, toString)); - } - - // Test equals - for (Object f2 : f0s) { - for (Object f3 : f1s) { - Object other = ctor.newInstance(f2, f3); - boolean isEqual = (boolean) equalsMethod.invoke(datum, other); - boolean isEqualReverse = (boolean) equalsMethod.invoke(other, datum); - boolean f0f2Equal = Objects.equals(f0, f2); - boolean f1f3Equal = Objects.equals(f1, f3); - if (fieldType[0] == FieldTypeKind.FLOAT) { - f0f2Equal = Float.compare((float)f0, (float)f2) == 0; - } else if (fieldType[0] == FieldTypeKind.DOUBLE) { - f0f2Equal = Double.compare((double)f0, (double)f2) == 0; - } - if (fieldType[1] == FieldTypeKind.FLOAT) { - f1f3Equal = Float.compare((float)f1, (float)f3) == 0; - } else if (fieldType[1] == FieldTypeKind.DOUBLE) { - f1f3Equal = Double.compare((double)f1, (double)f3) == 0; - } - boolean shouldEqual = f0f2Equal && f1f3Equal; - // @@@ fail - if (shouldEqual != isEqual) - System.err.println(String.format("Equals not as expected: %s %s/%s, %s %s/%s", - fieldType[0].clazz, f0, f2, - fieldType[1].clazz, f1, f3)); - if (isEqualReverse != isEqual) - fail(String.format("Equals not symmetric: %s %s/%s, %s %s/%s", - fieldType[0].clazz, f0, f2, - fieldType[1].clazz, f1, f3)); - - } - } - } - } - } catch (Throwable e) { - throw new AssertionError(e); - } - } -}
--- a/test/langtools/tools/javac/datum/DatumCanNotDeclaredFieldsWithSameName.java Tue Jun 18 04:37:43 2019 +0200 +++ /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=DatumCanNotDeclaredFieldsWithSameName.out -XDrawDiagnostics DatumCanNotDeclaredFieldsWithSameName.java - */ - -public class DatumCanNotDeclaredFieldsWithSameName { - record D1(int x, int x) { } -}
--- a/test/langtools/tools/javac/datum/DatumCanNotDeclaredFieldsWithSameName.out Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -DatumCanNotDeclaredFieldsWithSameName.java:8:26: compiler.err.record.cant.declare.duplicate.fields -1 error
--- a/test/langtools/tools/javac/datum/Neg01.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @summary smoke negative test for datum classes - * @compile/fail/ref=Neg01.out -XDrawDiagnostics Neg01.java - */ - -public class Neg01 { - static record Sup1(int x, int y) { } - - record Bad1(int x, int y, int z) extends Sup1(x, y) { } //can't extend - - static class Sup2 { } - - static record Sup3(int x, int y) { } -}
--- a/test/langtools/tools/javac/datum/Neg01.out Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -Neg01.java:10:37: compiler.err.expected: ';' -Neg01.java:10:46: compiler.err.invalid.meth.decl.ret.type.req -Neg01.java:10:52: compiler.err.expected: token.identifier -Neg01.java:10:55: compiler.err.expected: token.identifier -4 errors
--- a/test/langtools/tools/javac/datum/NoAddFieldsCanBeDeclaredInDatumTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @summary smoke negative test for datum classes - * @compile/fail/ref=NoAddFieldsCanBeDeclaredInDatumTest.out -XDrawDiagnostics NoAddFieldsCanBeDeclaredInDatumTest.java - */ - -public class NoAddFieldsCanBeDeclaredInDatumTest { - record Bad1(int i) { - int y; - } - - record Good1(int i) { - interface I {} - } - - record Good2(int i) { - static {} - } - - record Good3(int i) { - enum E {A, B} - } - - record Good4(int i) { - {} - } -}
--- a/test/langtools/tools/javac/datum/NoAddFieldsCanBeDeclaredInDatumTest.out Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -NoAddFieldsCanBeDeclaredInDatumTest.java:9:13: compiler.err.record.fields.must.be.in.header -1 error
--- a/test/langtools/tools/javac/datum/ParameterLessConstructorsTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +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 smoke test for parameterless constructors - * @compile ParameterLessConstructorsTest.java - */ - -import java.util.*; - -public record ParameterLessConstructorsTest(String s, String k) { - public ParameterLessConstructorsTest { - Objects.requireNonNull(s); - Objects.requireNonNull(k); - } -}
--- a/test/langtools/tools/javac/datum/Pos01.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2017, 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 smoke test for datum classes - * @run main Pos01 - */ -public class Pos01 { - - static void assertTrue(boolean cond) { - if (!cond) { - throw new AssertionError(); - } - } - - static record Sup(int x, int y) { } - - static record Foo(int x, int y, int z); - - public static void main(String[] args) { - Foo foo = new Foo(1, 2, 3); - Foo foo2 = new Foo(1, 2, 3); - Foo foo3 = new Foo(1, 2, 4); - assertTrue(foo.toString().equals("Foo[x=1, y=2, z=3]")); -// assertTrue(foo.hashCode() == java.util.Objects.hash(1, 2, 3)); - assertTrue(foo.equals(foo2)); - assertTrue(!foo.equals(foo3)); - assertTrue(foo.x() == 1); - assertTrue(foo.y() == 2); - assertTrue(foo.z() == 3); - } -}
--- a/test/langtools/tools/javac/datum/RecordsCanReDeclareMembersTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @summary records cannot explicitly declare hashCode or equals - * @compile RecordsCanReDeclareMembersTest.java - */ - -public record RecordsCanReDeclareMembersTest(int i) { - @Override - public int hashCode() { return 0; } - @Override - public boolean equals(Object o) { return true; } - @Override - public String toString() { return ""; } // toString() is OK - - public int i() { return i; } -}
--- a/test/langtools/tools/javac/datum/RecordsCantDeclareFieldModifiersTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /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/datum/RecordsCantDeclareFieldModifiersTest.out Tue Jun 18 04:37:43 2019 +0200 +++ /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/datum/UserDefinedAccessorsMustBePublic.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @summary smoke negative test for record classes - * @compile/fail/ref=UserDefinedAccessorsMustBePublic.out -XDrawDiagnostics UserDefinedAccessorsMustBePublic.java - */ - -public record UserDefinedAccessorsMustBePublic(int i) { - int i() { return i; } -}
--- a/test/langtools/tools/javac/datum/UserDefinedAccessorsMustBePublic.out Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -UserDefinedAccessorsMustBePublic.java:8:9: compiler.err.method.must.be.public: i -1 error
--- a/test/langtools/tools/javac/datum/UserDefinedMethodsTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2017, 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 smoke test for datum classes - * @modules jdk.compiler/com.sun.tools.javac.util - * @run main UserDefinedMethodsTest - */ - -import com.sun.tools.javac.util.Assert; - -public class UserDefinedMethodsTest { - - static record Foo(int x, int y, int z) { - @Override - public String toString() { - return "Foo(x=#x, y=#y, z=#z)".replaceAll("#x", "" + x).replaceAll("#y", "" + y).replaceAll("#z", "" + z); - } - - String bar() { - return "bar"; - } - - String foo() { - return "Foo.foo"; - } - } - - public static void main(String[] args) { - Foo foo = new Foo(1, 2, 3); - Assert.check(foo.toString().equals("Foo(x=1, y=2, z=3)")); - Assert.check(foo.bar().equals("bar")); - Assert.check(foo.foo().equals("Foo.foo")); - } -}
--- a/test/langtools/tools/javac/datum/allow_static_fields/AllowStaticFieldsInRecordsTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2017, 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. - * - * 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 smoke test to check that static fields are allowed in records - * @compile AllowStaticFieldsInRecordsTest.java - */ - -public record AllowStaticFieldsInRecordsTest(int x) { - static int I = 1; - static final String S = "Hello World!"; - static private Object O = null; - static protected Object O2 = null; -}
--- a/test/langtools/tools/javac/datum/bodyless_interfaces/AllowBodyLessInterfacesTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /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/datum/canonical_constructor/BadCanonicalConstructorTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @summary check that a datum can inherit from DataClass or an abstract datum class - * @compile/fail/ref=BadCanonicalConstructorTest.out -XDrawDiagnostics BadCanonicalConstructorTest.java - */ - -public class BadCanonicalConstructorTest { - record R1() { - private R1 {} - } - - record R2() { - protected R2 {} - } - - record R3() { - R3 {} - } -}
--- a/test/langtools/tools/javac/datum/canonical_constructor/BadCanonicalConstructorTest.out Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -BadCanonicalConstructorTest.java:9:17: compiler.err.method.must.be.public: <init> -BadCanonicalConstructorTest.java:13:19: compiler.err.method.must.be.public: <init> -BadCanonicalConstructorTest.java:17:9: compiler.err.method.must.be.public: <init> -3 errors
--- a/test/langtools/tools/javac/datum/canonical_constructor/CanonicalConstructorTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2019, 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 testing the canonical constructor for records - * @modules jdk.compiler/com.sun.tools.javac.util - */ - -import com.sun.tools.javac.util.Assert; - -public class CanonicalConstructorTest { - record R1(int i, int j); - record R2(int i, int j) { - public R2 {} - } - record R3(int i, int j) { - public R3 { - this.i = i; - } - } - record R4(int i, int j) { - public R4 { - this.i = i; - this.j = j; - } - } - - public static void main(String... args) { - R1 r1 = new R1(1, 2); - R2 r2 = new R2(1, 2); - R3 r3 = new R3(1, 2); - R4 r4 = new R4(1, 2); - - Assert.check(r1.i == r2.i && r2.i == r3.i && r3.i == r4.i && r4.i == 1 && r1.j == r2.j && r2.j == r3.j && r3.j == r4.j && r4.j == 2, "unexpected value of record component"); - } -}
--- a/test/langtools/tools/javac/datum/fields/RecordFieldsTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +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. - * - * 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 check the existence of private fields with same name and signature of the - * declared record components - * @modules jdk.compiler/com.sun.source.util - * jdk.compiler/com.sun.tools.javac.api - * jdk.compiler/com.sun.tools.javac.code - * jdk.compiler/com.sun.tools.javac.file - * jdk.compiler/com.sun.tools.javac.util - * @ignore - */ - -/* - this test is failing with a message saying that: Field "i" in class RecordFieldsTest has illegal signature "Ljava/util/List<Ljava/lang/String;>;" - */ - -import java.lang.reflect.*; -import java.util.*; - -//import com.sun.tools.javac.util.Assert; - -public record RecordFieldsTest(List<String> i) { - - public static void main(String... args) { - RecordFieldsTest r = new RecordFieldsTest(null); - Class<?> classOfRecord = r.getClass(); - Field[] fields = classOfRecord.getDeclaredFields(); - for (Field f: fields) { - System.out.println("field " + f.toString()); - //Assert.check(Modifier.isPrivate(f.getModifiers())); - System.out.println("type: " + f.getType()); - System.out.println("signature: " + f.toGenericString()); - } - } -}
--- a/test/langtools/tools/javac/datum/nested_records_must_be_static_and_final/NestedRecordsMustBeStaticAndFinalTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2017, 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. - * - * 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 check that records are always static - * @library /tools/javac/lib - * @modules jdk.compiler/com.sun.source.util - * jdk.compiler/com.sun.tools.javac.api - * jdk.compiler/com.sun.tools.javac.code - * jdk.compiler/com.sun.tools.javac.file - * jdk.compiler/com.sun.tools.javac.tree - * jdk.compiler/com.sun.tools.javac.util - * @build DPrinter - * @run main NestedRecordsMustBeStaticAndFinalTest - */ - -import java.io.*; -import java.net.URI; -import java.util.Arrays; - -import javax.tools.JavaCompiler; -import javax.tools.JavaFileObject; -import javax.tools.SimpleJavaFileObject; -import javax.tools.ToolProvider; - -import com.sun.source.tree.CompilationUnitTree; -import com.sun.source.util.JavacTask; -import com.sun.source.util.Trees; -import com.sun.tools.javac.api.JavacTrees; -import com.sun.tools.javac.file.JavacFileManager; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.Assert; -import com.sun.tools.javac.util.Context; - -public class NestedRecordsMustBeStaticAndFinalTest { - public static void main(String... args) throws Exception { - new NestedRecordsMustBeStaticAndFinalTest().run(); - } - - void run() throws Exception { - Context context = new Context(); - JavacFileManager.preRegister(context); - Trees trees = JavacTrees.instance(context); - strOut = new StringWriter(); - PrintWriter pw = new PrintWriter(strOut); - dprinter = new DPrinter(pw, trees); - tool = ToolProvider.getSystemJavaCompiler(); - test("Foo.java", source1); - test("Foo2.java", source11); - test("Foo3.java", source111); - test("Bar.java", source2); - test("Bar2.java", source3); - test("Baz.java", source4); - } - - StringWriter strOut; - DPrinter dprinter; - JavaCompiler tool; - - void test(String fileName, String source) throws Exception { - JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(new JavaSource(fileName, source))); - Iterable<? extends CompilationUnitTree> elements = ct.parse(); - Assert.check(elements.iterator().hasNext()); - dprinter.treeTypes(true).printTree("", (JCTree)elements.iterator().next()); - String output = strOut.toString(); - Assert.check(output.contains("flags: [static, final, record]"), "nested records should be static and final"); - } - - static final String source1 = - "class Foo {\n" + - " record R (int x);\n" + - "}"; - - static final String source11 = - "class Foo2 {\n" + - " class Inner {\n" + - " record R (int x);\n" + - " }\n" + - "}"; - static final String source111 = - "class Foo3 {\n" + - " Runnable r = new Runnable() {\n" + - " record R(int i);\n" + - " public void run() {}\n" + - " };" + - "}"; - static final String source2 = - "class Bar {\n" + - " void m() {\n" + - " record R (int x);\n" + - " }\n" + - "}"; - - static final String source3 = - "class Bar2 {\n" + - " void m() {\n" + - " static record R (int x);\n" + - " }\n" + - "}"; - - static final String source4 = - "class Baz {\n" + - " void m() {\n" + - " Runnable r = () -> {" + - " record R (int x);\n" + - " };\n" + - " }\n" + - "}"; - - static class JavaSource extends SimpleJavaFileObject { - - String source; - - public JavaSource(String fileName, String source) { - super(URI.create("myfo:/" + fileName), JavaFileObject.Kind.SOURCE); - this.source = source; - } - - @Override - public CharSequence getCharContent(boolean ignoreEncodingErrors) { - return source; - } - } -}
--- a/test/langtools/tools/javac/datum/records_cant_be_abstract/RecordsCantBeAbstractTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @summary smoke negative test for datum classes - * @compile/fail/ref=RecordsCantBeAbstractTest.out -XDrawDiagnostics RecordsCantBeAbstractTest.java - */ - -abstract record RecordsCantBeAbstractTest(int i);
--- a/test/langtools/tools/javac/datum/records_cant_be_abstract/RecordsCantBeAbstractTest.out Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -RecordsCantBeAbstractTest.java:7:1: compiler.err.record.cant.be.abstract -1 error
--- a/test/langtools/tools/javac/datum/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @summary check that a datum can inherit from DataClass or an abstract datum class - * @compile/fail/ref=RecordsCantHaveExtendsClause.out -XDrawDiagnostics RecordsCantHaveExtendsClause.java - */ - -import java.io.Serializable; - -class RecordsCantHaveExtendsClause { - - // even Object which is the implicit super class for records - record R1(int x) extends Object {} - - record R2(int y); - - // can't extend other records either - record R3(int y, int x) extends R2(y); - - // records can implement interfaces - record R4() implements Serializable, Runnable { - public void run() {} - } -}
--- a/test/langtools/tools/javac/datum/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.out Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -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
--- a/test/langtools/tools/javac/datum/writeread/Record.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2019, 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. - */ - -record Record1(int i, int j);
--- a/test/langtools/tools/javac/datum/writeread/WriteReadTest.java Tue Jun 18 04:37:43 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2019, 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 Verify javac can read record classfiles it writes - * @compile Record.java - * @compile WriteReadTest.java - */ -public class WriteReadTest { - - Record1 r1; - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/BadRecord.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,52 @@ +/* + * @test /nodynamiccopyright/ + * @summary Verifying error recovery for broken record classes + * @compile/fail/ref=BadRecord.out -XDrawDiagnostics BadRecord.java + */ +record BadRecordb1 {} + +record BadRecordb2( {} + +record BadRecordb3(int {} + +record BadRecordb4(int) {} + +record BadRecordb5(int i {} + +record BadRecordb6(int i, {} + +record BadRecordb7(int i,) {} + +record BadRecordb8(int i, int {} + +record BadRecordb9(int i, int) {} + +record BadRecordba(int i, int j {} + +record BadRecordbb(int i, int j, {} + +record BadRecordbc(int i, int j,) {} + +record BadRecords1; + +record BadRecords2(; + +record BadRecords3(int; + +record BadRecords4(int); + +record BadRecords5(int i; + +record BadRecords6(int i,; + +record BadRecords7(int i,); + +record BadRecords8(int i, int; + +record BadRecords9(int i, int); + +record BadRecordsa(int i, int j; + +record BadRecordsb(int i, int j,; + +record BadRecordsc(int i, int j,);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/BadRecord.out Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,25 @@ +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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/BadUseOfRecordKeywordTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,18 @@ +/* + * @test /nodynamiccopyright/ + * @summary check that record is not used as a type name + * @compile/fail/ref=BadUseOfRecordKeywordTest.out -XDrawDiagnostics BadUseOfRecordKeywordTest.java + */ + +class BadUseOfRecordKeywordTest { + + interface record { + void m(); + } + + class record {} + + enum record {A, B} + + record record(int x); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/BadUseOfRecordKeywordTest.out Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,5 @@ +BadUseOfRecordKeywordTest.java:9:15: compiler.err.record.not.allowed: record +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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/UserDefinedMethodsTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017, 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 smoke test for datum classes + * @modules jdk.compiler/com.sun.tools.javac.util + * @run main UserDefinedMethodsTest + */ + +import com.sun.tools.javac.util.Assert; + +public class UserDefinedMethodsTest { + + static record Foo(int x, int y, int z) { + @Override + public String toString() { + return "Foo(x=#x, y=#y, z=#z)".replaceAll("#x", "" + x).replaceAll("#y", "" + y).replaceAll("#z", "" + z); + } + + String bar() { + return "bar"; + } + + String foo() { + return "Foo.foo"; + } + } + + public static void main(String[] args) { + Foo foo = new Foo(1, 2, 3); + Assert.check(foo.toString().equals("Foo(x=1, y=2, z=3)")); + Assert.check(foo.bar().equals("bar")); + Assert.check(foo.foo().equals("Foo.foo")); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/allow_static_fields/AllowStaticFieldsInRecordsTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017, 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. + * + * 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 smoke test to check that static fields are allowed in records + * @compile AllowStaticFieldsInRecordsTest.java + */ + +public record AllowStaticFieldsInRecordsTest(int x) { + static int I = 1; + static final String S = "Hello World!"; + static private Object O = null; + static protected Object O2 = null; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/bodyless_interfaces/AllowBodyLessInterfacesTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,35 @@ +/* + * 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; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/fields/CheckDatumMembersAccess.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017, 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. + * + * 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 check that members of abtract datum has protected access + * @modules jdk.jdeps/com.sun.tools.classfile + * jdk.compiler/com.sun.tools.javac.util + * @compile CheckDatumMembersAccess.java + * @run main CheckDatumMembersAccess + */ + +import com.sun.tools.classfile.ClassFile; + +import java.io.File; + +import com.sun.tools.classfile.AccessFlags; +import com.sun.tools.classfile.Field; +import com.sun.tools.classfile.Method; +import com.sun.tools.javac.util.Assert; + +public class CheckDatumMembersAccess { + + record Datum(int field) {} + + public static void main(String args[]) throws Throwable { + new CheckDatumMembersAccess().run(); + } + + void run() throws Throwable { + checkNonAbstractDatum(); + } + + void checkNonAbstractDatum() throws Throwable { + File testClasses = new File(System.getProperty("test.classes")); + File file = new File(testClasses, + CheckDatumMembersAccess.class.getName() + "$Datum.class"); + ClassFile classFile = ClassFile.read(file); + for (Field f : classFile.fields) { + if (f.getName(classFile.constant_pool).equals("field")) { + Assert.check((f.access_flags.flags & (AccessFlags.ACC_FINAL)) != 0, "record fields should be final"); + Assert.check((f.access_flags.flags & (AccessFlags.ACC_PRIVATE)) != 0, "record fields should be private"); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/fields/DatumCanNotDeclaredFieldsWithSameName.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,9 @@ +/* + * @test /nodynamiccopyright/ + * @summary smoke negative test for datum classes + * @compile/fail/ref=DatumCanNotDeclaredFieldsWithSameName.out -XDrawDiagnostics DatumCanNotDeclaredFieldsWithSameName.java + */ + +public class DatumCanNotDeclaredFieldsWithSameName { + record D1(int x, int x) { } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/fields/DatumCanNotDeclaredFieldsWithSameName.out Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,2 @@ +DatumCanNotDeclaredFieldsWithSameName.java:8:26: compiler.err.record.cant.declare.duplicate.fields +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/fields/NoAddInstanceFieldsCanBeDeclaredInDatumTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,27 @@ +/* + * @test /nodynamiccopyright/ + * @summary smoke negative test for datum classes + * @compile/fail/ref=NoAddInstanceFieldsCanBeDeclaredInDatumTest.out -XDrawDiagnostics NoAddInstanceFieldsCanBeDeclaredInDatumTest.java + */ + +public class NoAddInstanceFieldsCanBeDeclaredInDatumTest { + record Bad1(int i) { + int y; + } + + record Good1(int i) { + interface I {} + } + + record Good2(int i) { + static {} + } + + record Good3(int i) { + enum E {A, B} + } + + record Good4(int i) { + {} + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/fields/NoAddInstanceFieldsCanBeDeclaredInDatumTest.out Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,2 @@ +NoAddInstanceFieldsCanBeDeclaredInDatumTest.java:9:13: compiler.err.record.fields.must.be.in.header +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/fields/RecordFieldsTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,58 @@ +/* + * 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. + * + * 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 check the existence of private fields with same name and signature of the + * declared record components + * @modules jdk.compiler/com.sun.source.util + * jdk.compiler/com.sun.tools.javac.api + * jdk.compiler/com.sun.tools.javac.code + * jdk.compiler/com.sun.tools.javac.file + * jdk.compiler/com.sun.tools.javac.util + * @ignore + */ + +/* + this test is failing with a message saying that: Field "i" in class RecordFieldsTest has illegal signature "Ljava/util/List<Ljava/lang/String;>;" + */ + +import java.lang.reflect.*; +import java.util.*; + +//import com.sun.tools.javac.util.Assert; + +public record RecordFieldsTest(List<String> i) { + + public static void main(String... args) { + RecordFieldsTest r = new RecordFieldsTest(null); + Class<?> classOfRecord = r.getClass(); + Field[] fields = classOfRecord.getDeclaredFields(); + for (Field f: fields) { + System.out.println("field " + f.toString()); + //Assert.check(Modifier.isPrivate(f.getModifiers())); + System.out.println("type: " + f.getType()); + System.out.println("signature: " + f.toGenericString()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/fields/RecordsCantDeclareFieldModifiersTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,9 @@ +/* + * @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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/fields/RecordsCantDeclareFieldModifiersTest.out Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,2 @@ +RecordsCantDeclareFieldModifiersTest.java:8:14: compiler.err.record.cant.declare.field.modifiers +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/mandated_members/CheckRecordMembers.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2017, 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. + */ + +/** + * CheckRecordMembers + * + * @test + * @summary check that the accessors, equals, hashCode and toString methods + * work as expected + * @library /tools/javac/lib + * @modules jdk.compiler/com.sun.tools.javac.file + * jdk.compiler/com.sun.tools.javac.api + * jdk.compiler/com.sun.tools.javac.util + * @build combo.ComboTestHelper + + * @run main CheckRecordMembers + */ + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.tools.JavaFileObject; + +import com.sun.tools.javac.file.PathFileObject; +import combo.ComboTask; + +public class CheckRecordMembers extends combo.ComboInstance<CheckRecordMembers> { + + enum FieldTypeKind implements combo.ComboParameter { + BYTE("byte", byte.class), + SHORT("short", short.class), + CHAR("char", char.class), + INT("int", int.class), + LONG("long", long.class), + FLOAT("float", float.class), + DOUBLE("double", double.class), + BOOLEAN("boolean", boolean.class), + OBJECT("Object", Object.class), + STRING("String", String.class); + + String retTypeStr; + Class<?> clazz; + + FieldTypeKind(String retTypeStr, Class<?> clazz) { + this.retTypeStr = retTypeStr; + this.clazz = clazz; + } + + public String expand(String optParameter) { + return retTypeStr; + } + } + + static final Map<FieldTypeKind, List<Object>> dataValues + = Map.ofEntries( + Map.entry(FieldTypeKind.BYTE, List.of(Byte.MIN_VALUE, (byte) -4, (byte) -1, (byte) 0, (byte) 1, (byte) 4, Byte.MAX_VALUE)), + Map.entry(FieldTypeKind.SHORT, List.of(Short.MIN_VALUE, (short) -4, (short) -1, (short) 0, (short) 1, (short) 4, Short.MAX_VALUE)), + Map.entry(FieldTypeKind.CHAR, List.of(Character.MIN_VALUE, 'a', 'A', 'z', (char) 0, Character.MAX_VALUE)), + Map.entry(FieldTypeKind.INT, List.of(Integer.MIN_VALUE, (int) -4, (int) -1, (int) 0, (int) 1, (int) 4, Integer.MAX_VALUE)), + Map.entry(FieldTypeKind.LONG, List.of(Long.MIN_VALUE, (long) -4, (long) -1, (long) 0, (long) 1, (long) 4, Long.MAX_VALUE)), + Map.entry(FieldTypeKind.FLOAT, List.of(Float.MIN_VALUE, Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0f, -0.0f, 1.0f, -1.0f, 2.0f, -2.0f, Float.MAX_VALUE)), + Map.entry(FieldTypeKind.DOUBLE, List.of(Double.MIN_VALUE, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0.0d, -0.0d, 1.0d, -1.0d, 2.0d, -2.0d, Double.MAX_VALUE)), + Map.entry(FieldTypeKind.BOOLEAN, List.of(true, false)), + Map.entry(FieldTypeKind.OBJECT, Arrays.asList(null, 3, "foo", new String[] {"a"})), + Map.entry(FieldTypeKind.STRING, Arrays.asList(null, "", "foo", "bar")) + ); + + static final String sourceTemplate = + "record Data(#{FT[0]} f0, #{FT[1]} f1) { }"; + + public static void main(String... args) throws Exception { + new combo.ComboTestHelper<CheckRecordMembers>() + .withArrayDimension("FT", (x, t, index) -> { + x.fieldType[index] = t; + }, 2, FieldTypeKind.values()) + .run(CheckRecordMembers::new); + } + + FieldTypeKind[] fieldType = new FieldTypeKind[2]; + + @Override + public void doWork() throws Throwable { + newCompilationTask() + .withSourceFromTemplate(sourceTemplate) + .generate(this::check); + } + + void check(ComboTask.Result<Iterable<? extends JavaFileObject>> result) { + List<Object> f0s = dataValues.get(fieldType[0]); + List<Object> f1s = dataValues.get(fieldType[1]); + + if (result.hasErrors() || result.hasWarnings()) + fail("Compilation errors not expected: " + result.compilationInfo()); + + Iterable<? extends PathFileObject> pfoIt = (Iterable<? extends PathFileObject>) result.get(); + PathFileObject pfo = pfoIt.iterator().next(); + Class<?> clazz; + Constructor<?> ctor; + Method getterF0, getterF1, hashCodeMethod, equalsMethod, toStringMethod; + Field fieldF0, fieldF1; + + try { + URL[] urls = new URL[] {pfo.getPath().getParent().toUri().toURL()}; + ClassLoader cl = new URLClassLoader(urls); + clazz = cl.loadClass("Data"); + + ctor = clazz.getConstructor(fieldType[0].clazz, fieldType[1].clazz); + getterF0 = clazz.getMethod("f0"); + getterF1 = clazz.getMethod("f1"); + fieldF0 = clazz.getDeclaredField("f0"); + fieldF1 = clazz.getDeclaredField("f1"); + equalsMethod = clazz.getMethod("equals", Object.class); + hashCodeMethod = clazz.getMethod("hashCode"); + toStringMethod = clazz.getMethod("toString"); + + if (getterF0.getReturnType() != fieldType[0].clazz + || getterF1.getReturnType() != fieldType[1].clazz + || fieldF0.getType() != fieldType[0].clazz + || fieldF1.getType() != fieldType[1].clazz) + fail("Unexpected field or getter type: " + result.compilationInfo()); + + for (AccessibleObject o : List.of(ctor, getterF0, getterF1, equalsMethod, hashCodeMethod, toStringMethod)) { + // @@@ Why do we need this? + o.setAccessible(true); + } + + for (Object f0 : f0s) { + for (Object f1 : f1s) { + // Create object + Object datum = ctor.newInstance(f0, f1); + + // Test getters + Object actualF0 = getterF0.invoke(datum); + Object actualF1 = getterF1.invoke(datum); + if (!Objects.equals(f0, actualF0) || !Objects.equals(f1, actualF1)) + fail(String.format("Getters don't report back right values for %s %s/%s, %s %s/%s", + fieldType[0].clazz, f0, actualF0, + fieldType[1].clazz, f1, actualF1)); + + int hashCode = (int) hashCodeMethod.invoke(datum); + int expectedHash = Objects.hash(f0, f1); + // @@@ fail + if (hashCode != expectedHash) { + System.err.println(String.format("Hashcode not as expected: expected=%d, actual=%d", + expectedHash, hashCode)); + } + + String toString = (String) toStringMethod.invoke(datum); + String expectedToString = String.format("Data[f0=%s, f1=%s]", f0, f1); + if (!toString.equals(expectedToString)) { + fail(String.format("ToString not as expected: expected=%s, actual=%s", + expectedToString, toString)); + } + + // Test equals + for (Object f2 : f0s) { + for (Object f3 : f1s) { + Object other = ctor.newInstance(f2, f3); + boolean isEqual = (boolean) equalsMethod.invoke(datum, other); + boolean isEqualReverse = (boolean) equalsMethod.invoke(other, datum); + boolean f0f2Equal = Objects.equals(f0, f2); + boolean f1f3Equal = Objects.equals(f1, f3); + if (fieldType[0] == FieldTypeKind.FLOAT) { + f0f2Equal = Float.compare((float)f0, (float)f2) == 0; + } else if (fieldType[0] == FieldTypeKind.DOUBLE) { + f0f2Equal = Double.compare((double)f0, (double)f2) == 0; + } + if (fieldType[1] == FieldTypeKind.FLOAT) { + f1f3Equal = Float.compare((float)f1, (float)f3) == 0; + } else if (fieldType[1] == FieldTypeKind.DOUBLE) { + f1f3Equal = Double.compare((double)f1, (double)f3) == 0; + } + boolean shouldEqual = f0f2Equal && f1f3Equal; + // @@@ fail + if (shouldEqual != isEqual) + System.err.println(String.format("Equals not as expected: %s %s/%s, %s %s/%s", + fieldType[0].clazz, f0, f2, + fieldType[1].clazz, f1, f3)); + if (isEqualReverse != isEqual) + fail(String.format("Equals not symmetric: %s %s/%s, %s %s/%s", + fieldType[0].clazz, f0, f2, + fieldType[1].clazz, f1, f3)); + + } + } + } + } + } catch (Throwable e) { + throw new AssertionError(e); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/mandated_members/RecordsCanReDeclareMembersTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,16 @@ +/* + * @test /nodynamiccopyright/ + * @summary records cannot explicitly declare hashCode or equals + * @compile RecordsCanReDeclareMembersTest.java + */ + +public record RecordsCanReDeclareMembersTest(int i) { + @Override + public int hashCode() { return 0; } + @Override + public boolean equals(Object o) { return true; } + @Override + public String toString() { return ""; } // toString() is OK + + public int i() { return i; } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/mandated_members/UserDefinedAccessorsMustBePublic.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,9 @@ +/* + * @test /nodynamiccopyright/ + * @summary smoke negative test for record classes + * @compile/fail/ref=UserDefinedAccessorsMustBePublic.out -XDrawDiagnostics UserDefinedAccessorsMustBePublic.java + */ + +public record UserDefinedAccessorsMustBePublic(int i) { + int i() { return i; } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/mandated_members/UserDefinedAccessorsMustBePublic.out Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,2 @@ +UserDefinedAccessorsMustBePublic.java:8:9: compiler.err.method.must.be.public: i +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/mandated_members/canonical_constructor/BadCanonicalConstructorTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,19 @@ +/* + * @test /nodynamiccopyright/ + * @summary check that a datum can inherit from DataClass or an abstract datum class + * @compile/fail/ref=BadCanonicalConstructorTest.out -XDrawDiagnostics BadCanonicalConstructorTest.java + */ + +public class BadCanonicalConstructorTest { + record R1() { + private R1 {} + } + + record R2() { + protected R2 {} + } + + record R3() { + R3 {} + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/mandated_members/canonical_constructor/BadCanonicalConstructorTest.out Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,4 @@ +BadCanonicalConstructorTest.java:9:17: compiler.err.method.must.be.public: <init> +BadCanonicalConstructorTest.java:13:19: compiler.err.method.must.be.public: <init> +BadCanonicalConstructorTest.java:17:9: compiler.err.method.must.be.public: <init> +3 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/mandated_members/canonical_constructor/CanonicalConstructorTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2019, 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 testing the canonical constructor for records + * @modules jdk.compiler/com.sun.tools.javac.util + */ + +import com.sun.tools.javac.util.Assert; + +public class CanonicalConstructorTest { + record R1(int i, int j); + record R2(int i, int j) { + public R2 {} + } + record R3(int i, int j) { + public R3 { + this.i = i; + } + } + record R4(int i, int j) { + public R4 { + this.i = i; + this.j = j; + } + } + + public static void main(String... args) { + R1 r1 = new R1(1, 2); + R2 r2 = new R2(1, 2); + R3 r3 = new R3(1, 2); + R4 r4 = new R4(1, 2); + + Assert.check(r1.i == r2.i && r2.i == r3.i && r3.i == r4.i && r4.i == 1 && r1.j == r2.j && r2.j == r3.j && r3.j == r4.j && r4.j == 2, "unexpected value of record component"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/mandated_members/canonical_constructor/ParameterLessConstructorsTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,39 @@ +/* + * 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 smoke test for parameterless constructors + * @compile ParameterLessConstructorsTest.java + */ + +import java.util.*; + +public record ParameterLessConstructorsTest(String s, String k) { + public ParameterLessConstructorsTest { + Objects.requireNonNull(s); + Objects.requireNonNull(k); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/mandated_members/read_resolve_method/CheckReadResolveMethodTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,92 @@ +/* + * 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. + * + * 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 check that members of abtract datum has protected access + * @modules jdk.jdeps/com.sun.tools.classfile + * jdk.compiler/com.sun.tools.javac.util + * @compile CheckReadResolveMethodTest.java + * @run main CheckReadResolveMethodTest + */ + +import java.io.*; + +import com.sun.tools.classfile.*; + +public class CheckReadResolveMethodTest { + + // readResolve should be generated as a constructor is provided + record Point1(int i, int j) implements Serializable { + Point1(int i, int j) { + this.i = i; + this.j = j; + } + } + + // readResolve should be generated the record 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); + + // no readResolve should be generated as an implementation is already provided + record Point4(int i, int j) { + private Object readResolve() { + return new Point4(i, j); + } + } + + // no readResolve should be generated as an implementation of readObject is already provided + record Point5(int i, int j) { + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {} + } + + public static void main(String args[]) throws Throwable { + new CheckReadResolveMethodTest().run(); + } + + void run() throws Throwable { + checkReadResolveMethod("Point1", true); + checkReadResolveMethod("Point2", true); + checkReadResolveMethod("Point3", false); + checkReadResolveMethod("Point4", true); + checkReadResolveMethod("Point5", false); + } + + void checkReadResolveMethod(String className, boolean shouldBeThere) throws Throwable { + File testClasses = new File(System.getProperty("test.classes")); + File file = new File(testClasses, + CheckReadResolveMethodTest.class.getName() + "$" + className +".class"); + ClassFile classFile = ClassFile.read(file); + boolean found = false; + for (Method f : classFile.methods) { + if (f.getName(classFile.constant_pool).equals("readResolve")) { + found = true; + } + } + if (found != shouldBeThere) { + throw new AssertionError("incorrect generation of readResolve method at class " + className); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/nested_records_must_be_static_and_final/NestedRecordsMustBeStaticAndFinalTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2017, 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. + * + * 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 check that records are always static + * @library /tools/javac/lib + * @modules jdk.compiler/com.sun.source.util + * jdk.compiler/com.sun.tools.javac.api + * jdk.compiler/com.sun.tools.javac.code + * jdk.compiler/com.sun.tools.javac.file + * jdk.compiler/com.sun.tools.javac.tree + * jdk.compiler/com.sun.tools.javac.util + * @build DPrinter + * @run main NestedRecordsMustBeStaticAndFinalTest + */ + +import java.io.*; +import java.net.URI; +import java.util.Arrays; + +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.util.JavacTask; +import com.sun.source.util.Trees; +import com.sun.tools.javac.api.JavacTrees; +import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.util.Assert; +import com.sun.tools.javac.util.Context; + +public class NestedRecordsMustBeStaticAndFinalTest { + public static void main(String... args) throws Exception { + new NestedRecordsMustBeStaticAndFinalTest().run(); + } + + void run() throws Exception { + Context context = new Context(); + JavacFileManager.preRegister(context); + Trees trees = JavacTrees.instance(context); + strOut = new StringWriter(); + PrintWriter pw = new PrintWriter(strOut); + dprinter = new DPrinter(pw, trees); + tool = ToolProvider.getSystemJavaCompiler(); + test("Foo.java", source1); + test("Foo2.java", source11); + test("Foo3.java", source111); + test("Bar.java", source2); + test("Bar2.java", source3); + test("Baz.java", source4); + } + + StringWriter strOut; + DPrinter dprinter; + JavaCompiler tool; + + void test(String fileName, String source) throws Exception { + JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(new JavaSource(fileName, source))); + Iterable<? extends CompilationUnitTree> elements = ct.parse(); + Assert.check(elements.iterator().hasNext()); + dprinter.treeTypes(true).printTree("", (JCTree)elements.iterator().next()); + String output = strOut.toString(); + Assert.check(output.contains("flags: [static, final, record]"), "nested records should be static and final"); + } + + static final String source1 = + "class Foo {\n" + + " record R (int x);\n" + + "}"; + + static final String source11 = + "class Foo2 {\n" + + " class Inner {\n" + + " record R (int x);\n" + + " }\n" + + "}"; + static final String source111 = + "class Foo3 {\n" + + " Runnable r = new Runnable() {\n" + + " record R(int i);\n" + + " public void run() {}\n" + + " };" + + "}"; + static final String source2 = + "class Bar {\n" + + " void m() {\n" + + " record R (int x);\n" + + " }\n" + + "}"; + + static final String source3 = + "class Bar2 {\n" + + " void m() {\n" + + " static record R (int x);\n" + + " }\n" + + "}"; + + static final String source4 = + "class Baz {\n" + + " void m() {\n" + + " Runnable r = () -> {" + + " record R (int x);\n" + + " };\n" + + " }\n" + + "}"; + + static class JavaSource extends SimpleJavaFileObject { + + String source; + + public JavaSource(String fileName, String source) { + super(URI.create("myfo:/" + fileName), JavaFileObject.Kind.SOURCE); + this.source = source; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/records_cant_be_abstract/RecordsCantBeAbstractTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,7 @@ +/* + * @test /nodynamiccopyright/ + * @summary smoke negative test for datum classes + * @compile/fail/ref=RecordsCantBeAbstractTest.out -XDrawDiagnostics RecordsCantBeAbstractTest.java + */ + +abstract record RecordsCantBeAbstractTest(int i);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/records_cant_be_abstract/RecordsCantBeAbstractTest.out Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,2 @@ +RecordsCantBeAbstractTest.java:7:1: compiler.err.record.cant.be.abstract +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,23 @@ +/* + * @test /nodynamiccopyright/ + * @summary check that a datum can inherit from DataClass or an abstract datum class + * @compile/fail/ref=RecordsCantHaveExtendsClause.out -XDrawDiagnostics RecordsCantHaveExtendsClause.java + */ + +import java.io.Serializable; + +class RecordsCantHaveExtendsClause { + + // even Object which is the implicit super class for records + record R1(int x) extends Object {} + + record R2(int y); + + // can't extend other records either + record R3(int y, int x) extends R2(y); + + // records can implement interfaces + record R4() implements Serializable, Runnable { + public void run() {} + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/records_cant_have_extends_clause/RecordsCantHaveExtendsClause.out Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,6 @@ +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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/writeread/Record.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2019, 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. + */ + +import java.util.List; + +record Record1<T>(int i, int j, List<String> ls, List<T> lt);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/writeread/WriteReadTest.java Tue Jun 18 21:30:24 2019 +0200 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019, 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 Verify javac can read record classfiles it writes + * @compile Record.java + * @compile WriteReadTest.java + */ +public class WriteReadTest { + + Record1 r1; + +}