Skip to content

Commit

Permalink
Add regression test for record annotations
Browse files Browse the repository at this point in the history
This adds a JDK 17+ test project and adds a regression test
for the fix described in issue oracle#3984
  • Loading branch information
jerboaa committed Mar 24, 2022
1 parent d6ed604 commit a003dec
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 0 deletions.
19 changes: 19 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,24 @@
"spotbugs": "false",
},

"com.oracle.svm.test.jdk17": {
"subDir": "src",
"sourceDirs": ["src"],
"dependencies": [
"mx:JUNIT_TOOL",
"sdk:GRAAL_SDK",
"SVM",
],
"checkstyle": "com.oracle.svm.test",
"workingSets": "SVM",
"annotationProcessors": [
"compiler:GRAAL_PROCESSOR",
],
"javaCompliance": "17+",
"spotbugs": "false",
"testProject": True,
},

"com.oracle.svm.configure.test": {
"subDir": "src",
"sourceDirs": ["src"],
Expand Down Expand Up @@ -1497,6 +1515,7 @@
"relpath" : True,
"dependencies" : [
"com.oracle.svm.test",
"com.oracle.svm.test.jdk17",
"com.oracle.svm.configure.test",
"com.oracle.svm.graal.test",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2022, 2022, 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.
*/

package com.oracle.svm.test.jdk17.recordannotations;

// Main record under test. See Main.
@RCA2
record F(@RCA @RCA2 String name, @RCA2 int i) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022, 2022, 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.
*/

package com.oracle.svm.test.jdk17.recordannotations;

import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.RECORD_COMPONENT, ElementType.FIELD })
@interface RCA {
// empty
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2022, 2022, 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.
*/

package com.oracle.svm.test.jdk17.recordannotations;

import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.RECORD_COMPONENT, ElementType.FIELD, ElementType.TYPE })
@interface RCA2 {
// empty
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2022, 2022, 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.
*/

package com.oracle.svm.test.jdk17.recordannotations;

import java.lang.annotation.Annotation;
import java.lang.reflect.RecordComponent;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;

public class RecordAnnotationsTest {

@Test
public void verifyRecordAnnotations() {
F x = new F("x", 1);

RecordComponent[] recordComponents = x.getClass().getRecordComponents();
Assert.assertEquals(2, recordComponents.length);

// Avoid relying on order of returned record components
RecordComponent intComp = null;
RecordComponent stringComp = null;
for (RecordComponent c: recordComponents) {
if ("name".equals(c.getName())) {
stringComp = c;
}
if ("i".equals(c.getName())) {
intComp = c;
}
}
Assert.assertNotNull(stringComp);
Assert.assertNotNull(intComp);

// Verify String component annotations
List<Annotation> stringCompAnnot = Arrays.asList(stringComp.getAnnotations());
Assert.assertEquals("expected 2 record annotations for string component", 2, stringCompAnnot.size());
Assert.assertTrue("expected RCA component annotation", stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.jdk17.recordannotations.RCA")));
Assert.assertTrue("expected RCA2 component annotation", stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.jdk17.recordannotations.RCA2")));
Assert.assertEquals(String.class.getTypeName(), stringComp.getAnnotatedType().getType().getTypeName());
Annotation rcaAnnotation = stringComp.getAnnotation(RCA.class);
Assert.assertNotNull("expected RCA annotation to be present", rcaAnnotation);
Assert.assertEquals(String.class.getTypeName(), stringComp.getGenericType().getTypeName());

// Verify int component annotations
List<Annotation> intCompAnnot = Arrays.asList(intComp.getAnnotations());
Assert.assertEquals("expected 1 record annotation for int component", 1, intCompAnnot.size());
Assert.assertTrue("expected RCA2 component annotation", intCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.jdk17.recordannotations.RCA2")));
Assert.assertEquals(int.class.getTypeName(), intComp.getAnnotatedType().getType().getTypeName());
Assert.assertNull(intComp.getAnnotation(RCA.class));
Assert.assertNotNull(intComp.getAnnotation(RCA2.class));
Assert.assertEquals(int.class.getTypeName(), intComp.getGenericType().getTypeName());

Assert.assertEquals(1, x.i());
Assert.assertEquals("x", x.name());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"name" : "com.oracle.svm.test.jdk17.recordannotations.F",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredClasses" : true,
"allPublicClasses" : true
}
]

0 comments on commit a003dec

Please sign in to comment.