You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2026/09/09 07:38:29 UTC

[PR] GROOVY-12390: GStringImpl: constant-value check pulls the compiler's … [groovy]

paulk-asert opened a new pull request, #2912:
URL: https://github.com/apache/groovy/pull/2912

   …ClassHelper into the runtime


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12390: GStringImpl: constant-value check pulls the compiler's … [groovy]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2912:
URL: https://github.com/apache/groovy/pull/2912#issuecomment-5599386202

   ## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2912?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `91.66667%` with `1 line` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 71.1946%. Comparing base ([`17b99a8`](https://app.codecov.io/gh/apache/groovy/commit/17b99a8c6c942b207257090e7ce795b34f58d8b0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`fd5554d`](https://app.codecov.io/gh/apache/groovy/commit/fd5554d8bc70c90b0d7cf0586840b6d1f8bdd3ed?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2912?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...rg/apache/groovy/internal/util/ImmutableTypes.java](https://app.codecov.io/gh/apache/groovy/pull/2912?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Finternal%2Futil%2FImmutableTypes.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2dyb292eS9pbnRlcm5hbC91dGlsL0ltbXV0YWJsZVR5cGVzLmphdmE=) | 87.5000% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/groovy/pull/2912?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/groovy/pull/2912/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/2912?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #2912        +/-   ##
   ==================================================
   + Coverage     71.1943%   71.1946%   +0.0002%     
   - Complexity      37632      37635         +3     
   ==================================================
     Files            1581       1582         +1     
     Lines          136251     136252         +1     
     Branches        25311      25310         -1     
   ==================================================
   + Hits            97003      97004         +1     
     Misses          30511      30511                
     Partials         8737       8737                
   ```
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2912?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...pache/groovy/ast/tools/ImmutablePropertyUtils.java](https://app.codecov.io/gh/apache/groovy/pull/2912?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fast%2Ftools%2FImmutablePropertyUtils.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2dyb292eS9hc3QvdG9vbHMvSW1tdXRhYmxlUHJvcGVydHlVdGlscy5qYXZh) | `74.0741% <100.0000%> (-0.9259%)` | :arrow_down: |
   | [.../java/org/codehaus/groovy/runtime/GStringImpl.java](https://app.codecov.io/gh/apache/groovy/pull/2912?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fruntime%2FGStringImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3J1bnRpbWUvR1N0cmluZ0ltcGwuamF2YQ==) | `95.6522% <100.0000%> (ø)` | |
   | [...rg/apache/groovy/internal/util/ImmutableTypes.java](https://app.codecov.io/gh/apache/groovy/pull/2912?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Finternal%2Futil%2FImmutableTypes.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2dyb292eS9pbnRlcm5hbC91dGlsL0ltbXV0YWJsZVR5cGVzLmphdmE=) | `87.5000% <87.5000%> (ø)` | |
   
   ... and [13 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2912/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12390: GStringImpl: constant-value check pulls the compiler's … [groovy]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2912:
URL: https://github.com/apache/groovy/pull/2912#discussion_r3968801371


##########
src/test/groovy/org/codehaus/groovy/runtime/GStringImplRuntimeFootprintTest.groovy:
##########
@@ -0,0 +1,89 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.runtime
+
+import groovy.transform.KnownImmutable
+import org.apache.groovy.ast.tools.ImmutablePropertyUtils
+import org.codehaus.groovy.ast.ClassHelper
+import org.apache.groovy.internal.util.ImmutableTypes
+import org.junit.jupiter.api.Test
+
+import static org.junit.jupiter.api.Assertions.assertEquals
+import static org.junit.jupiter.api.Assertions.assertFalse
+import static org.junit.jupiter.api.Assertions.assertTrue
+
+/**
+ * GROOVY-12390: building a GString must not initialise the compiler's AST
+ * model; the immutable-type check it needs lives in a runtime utility.
+ */
+final class GStringImplRuntimeFootprintTest {
+
+    private static final class RecordingLoader extends URLClassLoader {
+        final List<String> loaded = []
+        final Map<String, String> firstUse = [:]
+        RecordingLoader(URL[] urls) { super(urls, ClassLoader.platformClassLoader) }

Review Comment:
   `ClassLoader.platformClassLoader` relies on `ClassLoader.getPlatformClassLoader()` (Java 9+). If this project still compiles/tests on Java 8, this test won’t compile. Consider using a Java-8-compatible parent (e.g., `ClassLoader.getSystemClassLoader().getParent()`) or selecting the platform classloader via reflection with a fallback.



##########
src/main/java/org/apache/groovy/internal/util/ImmutableTypes.java:
##########
@@ -0,0 +1,160 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.groovy.internal.util;
+
+import org.apache.groovy.lang.annotation.Incubating;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+/**
+ * The types and marker annotations Groovy treats as immutable, shared by the
+ * {@code @Immutable} family of transforms and by the runtime (GROOVY-12390).
+ * <p>
+ * Lives outside the AST packages on purpose: {@code GStringImpl} consults it
+ * for every GString with a non-trivial value, and reaching it through the
+ * transform utilities would initialise the compiler's {@code ClassHelper},
+ * with its reflective model of the JDK types, in an application that never
+ * compiles anything. Not part of the public API.

Review Comment:
   The Javadoc states “Not part of the public API” while the class is `public` and annotated `@Incubating`, which typically signals a (new) supported API surface. To avoid mixed signals for consumers, either (a) remove `@Incubating` and clearly mark it as internal-only (if there is an internal annotation/convention), or (b) adjust the Javadoc to match the intended API status (e.g., ‘public but internal/subject to change’).



##########
src/test/groovy/org/codehaus/groovy/runtime/GStringImplRuntimeFootprintTest.groovy:
##########
@@ -0,0 +1,89 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.runtime
+
+import groovy.transform.KnownImmutable
+import org.apache.groovy.ast.tools.ImmutablePropertyUtils
+import org.codehaus.groovy.ast.ClassHelper
+import org.apache.groovy.internal.util.ImmutableTypes
+import org.junit.jupiter.api.Test
+
+import static org.junit.jupiter.api.Assertions.assertEquals
+import static org.junit.jupiter.api.Assertions.assertFalse
+import static org.junit.jupiter.api.Assertions.assertTrue
+
+/**
+ * GROOVY-12390: building a GString must not initialise the compiler's AST
+ * model; the immutable-type check it needs lives in a runtime utility.
+ */
+final class GStringImplRuntimeFootprintTest {
+
+    private static final class RecordingLoader extends URLClassLoader {
+        final List<String> loaded = []
+        final Map<String, String> firstUse = [:]
+        RecordingLoader(URL[] urls) { super(urls, ClassLoader.platformClassLoader) }
+        @Override
+        protected Class<?> loadClass(String name, boolean resolve) {
+            if (name.startsWith('org.codehaus.groovy.') || name.startsWith('org.apache.groovy.') || name.startsWith('groovy.')) loaded << name
+            if (name in WATCHED && !firstUse.containsKey(name)) {
+                firstUse[name] = new Throwable().stackTrace.findAll { !it.className.startsWith('java.') && !it.className.contains('RecordingLoader') }.take(12).join('\n')
+            }
+            super.loadClass(name, resolve)

Review Comment:
   Overriding `ClassLoader#loadClass` without preserving the usual per-class loading lock can introduce race conditions (e.g., duplicate-definition/LinkageError) if classloading ever becomes concurrent. Even though this is test code, it’s safer to wrap the logging/recording + `super.loadClass` call with `synchronized (getClassLoadingLock(name)) { ... }` (or make the method `synchronized`) to match the standard classloading contract.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12390: GStringImpl: constant-value check pulls the compiler's … [groovy]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2912:
URL: https://github.com/apache/groovy/pull/2912#issuecomment-5601792337

   ## ✅ All tests passed ✅
   
   🏷️ Commit: fd5554d8bc70c90b0d7cf0586840b6d1f8bdd3ed
   ▶️ Tests:  113436 executed
   ⚪️ Checks: 33/33 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12390: GStringImpl: constant-value check pulls the compiler's … [groovy]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2912:
URL: https://github.com/apache/groovy/pull/2912#issuecomment-5609444651

   ## ✅ All tests passed ✅
   
   🏷️ Commit: a042f6a6e913bde5ba09c7ed42b7ac279a52fcd5
   ▶️ Tests:  116334 executed
   ⚪️ Checks: 33/33 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12390: GStringImpl: constant-value check pulls the compiler's … [groovy]

Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert merged PR #2912:
URL: https://github.com/apache/groovy/pull/2912


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org