You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/09/18 12:40:52 UTC

(groovy) branch master updated: GROOVY-12419: reachability metadata omits ImmutableASTTransformation.checkPropNames

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 b651968070 GROOVY-12419: reachability metadata omits ImmutableASTTransformation.checkPropNames
b651968070 is described below

commit b6519680700262aebb657af82b91a2e7971f644a
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Sep 18 13:30:04 2026 +1000

    GROOVY-12419: reachability metadata omits ImmutableASTTransformation.checkPropNames
    
    Enum constants and named-argument constructors are compiled to a call of
    ImmutableASTTransformation.checkPropNames made by name at run time, so the
    class needs a metaclass and reflectable methods in a native image, where
    the exact-metadata probe failed with MissingReflectionRegistrationError on
    its first enum. The generator now lists the class with the introspected
    runtime types, and the native probe constructs an enum and a @MapConstructor
    class so the drift check keeps covering the path.
---
 .../groovy/tools/NativeImageMetadataGenerator.java |  2 +
 .../tests-native/src/main/groovy/probe.groovy      | 18 +++++
 .../tests-native/reachability-metadata.json        | 86 +++++++++++++++++++++-
 3 files changed, 105 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/tools/NativeImageMetadataGenerator.java b/src/main/java/org/codehaus/groovy/tools/NativeImageMetadataGenerator.java
index c2652f72a5..4ee1e5c5ff 100644
--- a/src/main/java/org/codehaus/groovy/tools/NativeImageMetadataGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/NativeImageMetadataGenerator.java
@@ -61,6 +61,7 @@ import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
 import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl;
 import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
 import org.codehaus.groovy.runtime.typehandling.GroovyCastException;
+import org.codehaus.groovy.transform.ImmutableASTTransformation;
 import org.codehaus.groovy.vmplugin.VMPluginFactory;
 import org.codehaus.groovy.vmplugin.v17.Java17;
 import org.codehaus.groovy.vmplugin.v8.IndyArrayAccess;
@@ -197,6 +198,7 @@ public class NativeImageMetadataGenerator {
             Binding.class,
             NullObject.class,
             Reference.class, // holds a captured local variable that a closure reassigns
+            ImmutableASTTransformation.class, // checkPropNames, called by name from enum constants and named-argument constructors
     };
 
     /**
diff --git a/subprojects/tests-native/src/main/groovy/probe.groovy b/subprojects/tests-native/src/main/groovy/probe.groovy
index aafbefac1c..a53a481396 100644
--- a/subprojects/tests-native/src/main/groovy/probe.groovy
+++ b/subprojects/tests-native/src/main/groovy/probe.groovy
@@ -28,6 +28,7 @@ import groovy.concurrent.AsyncScope
 import groovy.json.JsonOutput
 import groovy.json.JsonSlurper
 import groovy.transform.CompileStatic
+import groovy.transform.MapConstructor
 import groovy.xml.MarkupBuilder
 import groovy.xml.XmlParser
 import groovy.xml.XmlSlurper
@@ -52,6 +53,20 @@ class Person implements Named {
     Person(String name) { this.name = name }
 }
 
+// enum constants and named-argument constructors are compiled to a call of
+// ImmutableASTTransformation.checkPropNames, made by name at run time
+enum Suit {
+    HEARTS('red'), SPADES('black')
+    final String colour
+    Suit(String colour) { this.colour = colour }
+}
+
+@MapConstructor
+class Card {
+    Suit suit
+    int rank
+}
+
 @CompileStatic
 class StaticHelper {
     static int twice(int n) { n * 2 }
@@ -75,6 +90,7 @@ Comparator<Integer> byValue = { a, b -> a <=> b }
 def sorted = [3, 1, 2].toSorted(byValue)
 def statically = StaticHelper.twice(21) + StaticHelper.join(['a', 'b']).size()
 float[] floats = ['1.5', '2.5']*.toFloat() as float[] // `as T[]` goes through the MOP on DefaultGroovyMethods itself
+def card = new Card(suit: Suit.HEARTS, rank: 7)
 def captured = 0
 [1, 2, 3].each { captured += it } // a reassigned captured local lives in a groovy.lang.Reference
 def async = AsyncScope.withScope { scope ->
@@ -120,6 +136,7 @@ println "sorted=$sorted"
 println "static=$statically"
 println "async=$async"
 println "captured=$captured floats=${floats.sum()}"
+println "card=${card.suit} ${card.suit.colour} ${card.rank} suits=${Suit.values()*.name()}"
 println "metaClass=${p.metaClass.class.simpleName} methods=${p.metaClass.methods.size() > 0}"
 println "nio lines=$lines counted=$counted first=$firstLine"
 println "xml names=$itemNames ids=$itemIds built=${built.contains('gamma')}"
@@ -129,4 +146,5 @@ assert itemNames == ['alpha', 'beta'] && itemIds == ['1', '2'] && built.contains
 assert back.point.x == 4 && back.point.y == 6 && back.names.size() == 3 && back.nested.ok == true
 assert total == 220 && curried(2) == 42 && p.x == 4
 assert person.greet() == 'hello, groovy' && sorted == [1, 2, 3] && statically == 45 && async == 42 && captured == 6 && floats.sum() == 4.0f
+assert card.suit == Suit.HEARTS && card.suit.colour == 'red' && card.rank == 7 && Suit.values().size() == 2
 println 'PROBE OK'
diff --git a/subprojects/tests-native/src/main/resources/META-INF/native-image/org.apache.groovy/tests-native/reachability-metadata.json b/subprojects/tests-native/src/main/resources/META-INF/native-image/org.apache.groovy/tests-native/reachability-metadata.json
index 5e098082c8..6a8e7f8cb4 100644
--- a/subprojects/tests-native/src/main/resources/META-INF/native-image/org.apache.groovy/tests-native/reachability-metadata.json
+++ b/subprojects/tests-native/src/main/resources/META-INF/native-image/org.apache.groovy/tests-native/reachability-metadata.json
@@ -1,5 +1,34 @@
 {
     "reflection": [
+        {
+            "type": "Card",
+            "methods": [
+                {
+                    "name": "<init>",
+                    "parameterTypes": [
+                        "java.util.Map"
+                    ]
+                },
+                {
+                    "name": "getRank",
+                    "parameterTypes": [
+                        
+                    ]
+                },
+                {
+                    "name": "getSuit",
+                    "parameterTypes": [
+                        
+                    ]
+                }
+            ]
+        },
+        {
+            "type": "CardBeanInfo"
+        },
+        {
+            "type": "CardCustomizer"
+        },
         {
             "type": "Named",
             "methods": [
@@ -139,7 +168,41 @@
             "type": "StaticHelperCustomizer"
         },
         {
-            "type": "android.app.Activity"
+            "type": "Suit",
+            "fields": [
+                {
+                    "name": "HEARTS"
+                }
+            ],
+            "methods": [
+                {
+                    "name": "$INIT",
+                    "parameterTypes": [
+                        "java.lang.Object[]"
+                    ]
+                },
+                {
+                    "name": "getColour",
+                    "parameterTypes": [
+                        
+                    ]
+                },
+                {
+                    "name": "values",
+                    "parameterTypes": [
+                        
+                    ]
+                }
+            ]
+        },
+        {
+            "type": "SuitBeanInfo"
+        },
+        {
+            "type": "SuitCustomizer"
+        },
+        {
+            "type": "Suit[]"
         },
         {
             "type": "groovy.concurrent.AsyncScope",
@@ -213,6 +276,9 @@
         {
             "type": "groovy.json.JsonSlurperCustomizer"
         },
+        {
+            "type": "groovy.runtime.metaclass.CardMetaClass"
+        },
         {
             "type": "groovy.runtime.metaclass.Named$Trait$HelperMetaClass"
         },
@@ -225,6 +291,9 @@
         {
             "type": "groovy.runtime.metaclass.StaticHelperMetaClass"
         },
+        {
+            "type": "groovy.runtime.metaclass.SuitMetaClass"
+        },
         {
             "type": "groovy.runtime.metaclass.groovy.concurrent.AsyncScopeMetaClass"
         },
@@ -589,6 +658,12 @@
         {
             "type": "java.lang.ClassCustomizer"
         },
+        {
+            "type": "java.lang.EnumBeanInfo"
+        },
+        {
+            "type": "java.lang.EnumCustomizer"
+        },
         {
             "type": "java.lang.FloatBeanInfo"
         },
@@ -636,6 +711,15 @@
         {
             "type": "java.lang.StringCustomizer"
         },
+        {
+            "type": "java.lang.module.ModuleFinder"
+        },
+        {
+            "type": "java.lang.reflect.AccessibleObject"
+        },
+        {
+            "type": "java.lang.reflect.TypeVariable"
+        },
         {
             "type": "java.nio.Buffer"
         },