groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <>
Subject RE: trySetAccessible for Java 9
Date Wed, 05 Jul 2017 17:07:18 GMT


I made this suggestion about a month ago! In Lucene/Elasticsearch we do everything with MethodHandles
that requires new Java 9 APIs (currently Elasticsearch’s Painless Script engine is the first
one that uses indy string concats!). In general I would not use an if/then/else construct
at all. Just try to get a MethodHandle to trySetAccessible(), if this fails get a MethodHandle
to a local/private method with same signature.


Finally you may need to adapt the MethodHandle to the right types and then call it _always_
with correct casting to make javac use correct types. Be sure to make the MethodHandle a static
final constant somewhere! This removed the need for a if/then/else on every call.


I may provide a patch, if you like. I’d just need some directions where to look at. Should
be a 10 liner.





Uwe Schindler 

ASF Member, Apache Lucene PMC / Committer

Bremen, Germany


From: Cédric Champeau [] 
Sent: Wednesday, July 5, 2017 6:55 PM
To: Russel Winder <>
Subject: Re: trySetAccessible for Java 9


Actually I'm realizing that the `MethodHandle` API came with Java 7. So we _can_ compile against
it. So I guess an option is to have the method handle redirect to `trySetAccessible` if the
detected runtime is Java 9, and a backport method if < 9.




2017-07-05 18:41 GMT+02:00 Russel Winder < <>

On Wed, 2017-07-05 at 18:28 +0200, Cédric Champeau wrote:
> Any suggestion?

How about leave Groovy 2.x as a "can only build on JDK8", and put all effort
for a JDK9 build on Groovy 3.x which, as I understand it requires JDK8 as a
runtime. This would seem to minimise hassle and maximise forward-looking
benefit. Unless I am missing something.

Dr Russel Winder     t:+44 20 7585 2200 <tel:%2B44%2020%207585%202200>    voip:sip: <> 
41 Buckmaster Road   m:+44 7770 465 077 <tel:%2B44%207770%20465%20077>
London SW11 1EN, UK  w: <>  skype:russel_winder


View raw message