Copilot commented on code in PR #2882:
URL: https://github.com/apache/groovy/pull/2882#discussion_r3942850502
##########
src/test/groovy/org/apache/groovy/internal/runtime/invoke/InvokerFactoryTest.groovy:
##########
@@ -474,9 +474,54 @@ final class InvokerFactoryTest {
}
//
-------------------------------------------------------------------------
- // Forced Step 3 through defineSteps (hidden non-public nestmate)
+ // Hidden hosts (GROOVY-12361): no step may bind a hidden declaring class
//
-------------------------------------------------------------------------
+ @Test
+ void testTryCreateDeclinesPublicHiddenHost() {
+ // The ProxyGeneratorAdapter shape: a public hidden nestmate whose
public
+ // method is a Step 1 candidate. Its trampoline would CHECKCAST the
+ // receiver to the hidden class name, which no loader can resolve, so
it
+ // defines fine but throws NoClassDefFoundError on first invoke.
+ byte[] bytes = emitStringPingClass(
+ 'org/apache/groovy/internal/runtime/invoke/PublicHiddenHost',
+ 'ping', 'hidden-pong', true)
+ Class<?> hiddenHost =
HiddenClassDefiner.tryDefineNestmate(InvokerFactory.LOOKUP, bytes, true)
+ assertNotNull(hiddenHost)
+ assertTrue((Boolean) Class.getMethod('isHidden').invoke(hiddenHost))
+ Method ping = javaGetMethod(hiddenHost, 'ping')
+
assertTrue(InvokerFactory.isPubliclyInvocableFromInvokerFactory(cm(ping)))
+ assertFalse(InvokerFactory.allTypesNameable(ping))
+
+ assertNull(InvokerFactory.tryCreate(cm(ping)), 'hidden declaring class
must not get a trampoline')
+ // the reflective path keeps working
+ Object host = ((Class) hiddenHost).getConstructor().newInstance()
+ assertEquals('hidden-pong', cm(ping).invoke(host, new Object[0]))
+ }
+
+ @Test
+ void testHiddenProxyStaysInvocablePastThreshold() {
Review Comment:
This test changes a JVM-global system property without taking the
system-properties resource lock. Other tests in this class that mutate
`PROPERTY_THRESHOLD` or related switches use
`@ResourceLock(Resources.SYSTEM_PROPERTIES)` (for example, lines 608–615);
without it, parallel JUnit execution can observe the temporary zero threshold
or overwrite the value being restored, making the suite flaky.
--
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]