Copilot commented on code in PR #2906:
URL: https://github.com/apache/groovy/pull/2906#discussion_r3968790727


##########
src/test/groovy/org/apache/groovy/util/HiddenClassDefinerTest.groovy:
##########
@@ -68,6 +68,17 @@ class HiddenClassDefinerTest {
      * Production Java call sites capture {@code MethodHandles.lookup()} in a
      * {@code static final} field of the nest-host class itself.
      */
+    @Test
+    void loadingTheDefinerDoesNotResolveLookupClassOption() {
+        // GROOVY-12384: the ClassOption array lives in a nested holder so 
that a runtime
+        // without hidden classes (Android's ART) can load the definer and ask 
isEnabled()
+        def optionArray = MethodHandles.Lookup.ClassOption[]
+        assert HiddenClassDefiner.declaredFields.every { it.type != 
optionArray }
+        assert HiddenClassDefiner.declaredClasses.any { holder ->
+            holder.declaredFields.any { it.type == optionArray }
+        }

Review Comment:
   `def optionArray = MethodHandles.Lookup.ClassOption[]` is not a valid way to 
obtain the array `Class` object in Groovy, and it also makes `optionArray` 
ambiguous (type vs. value). Use the array class literal instead so `Field.type` 
comparisons are correct (e.g., assign 
`MethodHandles.Lookup.ClassOption[].class` to `optionArray`).



##########
src/test/groovy/org/apache/groovy/util/HiddenClassDefinerTest.groovy:
##########
@@ -68,6 +68,17 @@ class HiddenClassDefinerTest {
      * Production Java call sites capture {@code MethodHandles.lookup()} in a
      * {@code static final} field of the nest-host class itself.
      */
+    @Test
+    void loadingTheDefinerDoesNotResolveLookupClassOption() {
+        // GROOVY-12384: the ClassOption array lives in a nested holder so 
that a runtime
+        // without hidden classes (Android's ART) can load the definer and ask 
isEnabled()
+        def optionArray = MethodHandles.Lookup.ClassOption[]
+        assert HiddenClassDefiner.declaredFields.every { it.type != 
optionArray }
+        assert HiddenClassDefiner.declaredClasses.any { holder ->
+            holder.declaredFields.any { it.type == optionArray }
+        }

Review Comment:
   This is a JUnit `@Test`, but it uses Groovy `assert` statements. If 
assertions are disabled in the test runtime, this test can become a no-op. 
Prefer JUnit Assertions (`assertTrue`/`assertFalse`/`assertAll`) here so the 
checks always execute under the test runner.



##########
src/test/groovy/org/codehaus/groovy/reflection/android/AndroidSupportTest.groovy:
##########
@@ -0,0 +1,43 @@
+/*
+ *  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.reflection.android
+
+import org.apache.groovy.internal.runtime.invoke.InvokerFactory
+import org.junit.jupiter.api.Test
+
+import static org.junit.jupiter.api.Assertions.assertFalse
+import static org.junit.jupiter.api.Assertions.assertTrue
+
+/**
+ * GROOVY-12384: Android is recognised by its VM name, so a JVM is never 
mistaken
+ * for it, whatever is on the class path.
+ */
+final class AndroidSupportTest {
+
+    @Test
+    void aJvmIsNotAndroid() {
+        assertFalse(System.getProperty('java.vm.name').startsWith('Dalvik'))

Review Comment:
   `System.getProperty('java.vm.name')` can be `null` (or access can be 
restricted), which would make `.startsWith('Dalvik')` throw at runtime. Make 
the assertion resilient by handling `null`/read failures (e.g., coerce to empty 
string or use a JUnit assumption to skip when the property can’t be read).



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to