[ 
https://issues.apache.org/jira/browse/GROOVY-12719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140041#comment-18140041
 ] 

ASF GitHub Bot commented on GROOVY-12719:
-----------------------------------------

codeconsole opened a new pull request, #3253:
URL: https://github.com/apache/groovy/pull/3253

   A dynamic `new` of a constructor that the JVM refuses to the caller fails 
with an internal error under invokedynamic:
   
   ```groovy
   class C extends ObjectInputStream {
       static ObjectInputStream make() {
           new ObjectInputStream()   // BUG! UNCAUGHT EXCEPTION: member is 
protected: java.io.ObjectInputStream.<init>
       }
   }
   C.make()
   ```
   
   5.0.8 and 6.0.0 fail the same way. The constructor selector unreflected the 
selected constructor with the lookup of the calling class and turned an 
`IllegalAccessException` into `GroovyBugError`. As the property selectors do 
since GROOVY-12314, it now treats the refusal as an access-control outcome and 
leaves the call to the meta-class, which reports "could not access 
constructor", as the call does without invokedynamic. A constructor that 
reflection can reach, such as a protected constructor of a class of another 
package in the unnamed module, is still called.
   
   ## Compatibility
   
   The exception changes from `GroovyBugError` to `GroovyRuntimeException`, the 
same one as without invokedynamic.
   
   ## Tests
   
   `IndyRefusedConstructorTest.testProtectedConstructorOfEncapsulatedJdkClass` 
fails with invokedynamic without the change; it runs with and without 
invokedynamic, and is skipped where the JVM opens `java.base/java.io`. 
`testProtectedConstructorOfClassOfAnotherPackage` pins the constructor that is 
still called. 4,598 tests in `org.codehaus.groovy.vmplugin.v8`, 
`org.codehaus.groovy.classgen.asm.sc`, `groovy.lang` and `gls` pass. The 
Checkstyle and CodeNarc gates pass.
   




> A dynamic new of a constructor the JVM refuses fails with GroovyBugError 
> under invokedynamic
> --------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12719
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12719
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 5.0.8, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {code:groovy}
> class C extends ObjectInputStream {
>     static ObjectInputStream make() {
>         new ObjectInputStream()
>     }
> }
> C.make()
> {code}
> *Actual:* {{org.codehaus.groovy.GroovyBugError: BUG! UNCAUGHT EXCEPTION: 
> member is protected: java.io.ObjectInputStream.<init>}}
> *Expected:* {{GroovyRuntimeException: could not access constructor: protected 
> java.io.ObjectInputStream()}}, as without invokedynamic.
> Cause: the constructor selector in {{Selector}} unreflects the selected 
> constructor with the lookup of the calling class and turns an 
> {{IllegalAccessException}} into {{GroovyBugError}}. The property selectors 
> treat that as an access-control outcome since GROOVY-12314.
> Verified on 5.0.8, 6.0.0 and master, on JDK 21.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to