This is an automated email from the ASF dual-hosted git repository.
paulk-asert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new e9b9cf1ec5 GROOVY-12027: Align CompilerConfiguration with JDK17
minimum (fix some tests and docs)
e9b9cf1ec5 is described below
commit e9b9cf1ec53ceb86f6b1e3cd88d630ab3234f3ca
Author: Paul King <[email protected]>
AuthorDate: Fri May 22 15:22:33 2026 +1000
GROOVY-12027: Align CompilerConfiguration with JDK17 minimum (fix some
tests and docs)
---
.../transform/RecordTypeASTTransformation.java | 11 ++++------
src/spec/doc/_records.adoc | 6 +++---
.../org/codehaus/groovy/classgen/RecordTest.groovy | 25 ----------------------
3 files changed, 7 insertions(+), 35 deletions(-)
diff --git
a/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java
index e7bcf72136..fbe97906ae 100644
---
a/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java
+++
b/src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java
@@ -195,7 +195,7 @@ public class RecordTypeASTTransformation extends
AbstractASTTransformation imple
/**
* Predicts whether {@code cNode} will be compiled as a native JVM record.
* Mirrors the decision logic in {@link #doProcessRecordType} (presence of
- * {@code @RecordBase}, target bytecode {@code >= 16}, and
+ * {@code @RecordBase}, target bytecode {@code >= 17}, and
* {@code @RecordOptions(mode != EMULATE)}) so callers running before the
* transform itself fires can act on the same outcome.
* <p>
@@ -290,12 +290,11 @@ public class RecordTypeASTTransformation extends
AbstractASTTransformation imple
}
stubs.forEach(cNode::removeMethod);
AnnotationNode options = getRecordOptions(cNode);
- RecordTypeMode mode = getMode(options, "mode");
String targetBytecode = (sourceUnit != null) ?
sourceUnit.getConfiguration().getTargetBytecode() : null;
- String message = (targetBytecode != null)
- ? "Expecting JDK16+ but found " + targetBytecode
- : "Expecting JDK16+ but unable to determine target bytecode";
List<PropertyNode> pList =
Collections.unmodifiableList(getInstanceProperties(cNode));
+ // At Groovy 6's JDK17 floor, wouldBeNativeRecord is true unless the
+ // user explicitly opted out via @RecordOptions(mode=EMULATE), so the
+ // "explicit NATIVE but JDK too old" arm is unreachable here.
boolean isNative = wouldBeNativeRecord(cNode, targetBytecode);
if (isNative) {
String scName = cNode.getUnresolvedSuperClass().getName();
@@ -318,8 +317,6 @@ public class RecordTypeASTTransformation extends
AbstractASTTransformation imple
rec.putNodeMetaData("_SKIPPABLE_ANNOTATIONS", Boolean.TRUE);
cNode.getRecordComponents().add(rec);
}
- } else if (mode == RecordTypeMode.NATIVE) {
- addError(message + " when attempting to create a native record",
cNode);
} else {
createBeanInfoClass(cNode);
}
diff --git a/src/spec/doc/_records.adoc b/src/spec/doc/_records.adoc
index 1d507fca06..841d1d45ed 100644
--- a/src/spec/doc/_records.adoc
+++ b/src/spec/doc/_records.adoc
@@ -309,11 +309,11 @@ The `@RecordOptions` annotation (part of `@RecordType`)
supports a `mode` annota
which can take one of three values (with `AUTO` being the default):
NATIVE::
-Produces a class similar to what Java would do. Produces an error when
compiling on JDKs earlier than JDK16.
+Produces a class similar to what Java would do.
EMULATE::
-Produces a record-like class for all JDK versions.
+Produces a record-like class.
AUTO::
-Produces a native record for JDK16+ and emulates the record otherwise.
+Equivalent to `NATIVE` at Groovy 6's JDK17+ baseline (default).
Whether you use the `record` keyword or the `@RecordType` annotation
is independent of the mode.
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
b/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
index d1ce196f38..a72a177801 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
+++ b/src/test/groovy/org/codehaus/groovy/classgen/RecordTest.groovy
@@ -246,31 +246,6 @@ final class RecordTest {
'''
}
- @Test
- void testRecordLikeOnJDK16withTargetBytecode15() {
- assumeTrue(isAtLeastJdk('16.0'))
-
- [email protected] = '15'
- assertScript shell, '''
- record Person(String name) {}
- assert Person.superclass != java.lang.Record
- '''
- }
-
- @Test
- void testAttemptedNativeRecordWithTargetBytecode15ShouldFail() {
- assumeTrue(isAtLeastJdk('16.0'))
-
- [email protected] = '15'
- def err = shouldFail shell, '''
- @RecordType(mode=RecordTypeMode.NATIVE)
- class Person {
- String name
- }
- '''
- assert err.message.contains('Expecting JDK16+ but found 15 when
attempting to create a native record')
- }
-
@Test
void testNativeRecordWithSuperClassShouldFail() {
assumeTrue(isAtLeastJdk('16.0'))