Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D576D200CC0 for ; Sun, 9 Jul 2017 14:34:30 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D3C481694C7; Sun, 9 Jul 2017 12:34:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D6A63169440 for ; Sun, 9 Jul 2017 14:34:28 +0200 (CEST) Received: (qmail 60157 invoked by uid 500); 9 Jul 2017 12:34:28 -0000 Mailing-List: contact dev-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list dev@groovy.apache.org Received: (qmail 60147 invoked by uid 99); 9 Jul 2017 12:34:28 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Jul 2017 12:34:28 +0000 Received: from VEGA (p4FC8B290.dip0.t-ipconnect.de [79.200.178.144]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 8D3C01A0029 for ; Sun, 9 Jul 2017 12:34:23 +0000 (UTC) From: "Uwe Schindler" To: References: <1499272911.21698.16.camel@winder.org.uk> <023c01d2f5b1$2acd9ba0$8068d2e0$@apache.org> <025d01d2f5b4$00eff550$02cfdff0$@apache.org> <027301d2f5b9$e449ea90$acddbfb0$@apache.org> <029d01d2f5d1$fe4bb4b0$fae31e10$@apache.org> <00f801d2f8a4$598ccb50$0ca661f0$@apache.org> In-Reply-To: <00f801d2f8a4$598ccb50$0ca661f0$@apache.org> Subject: RE: trySetAccessible for Java 9 Date: Sun, 9 Jul 2017 14:34:16 +0200 Message-ID: <010501d2f8af$b0df11a0$129d34e0$@apache.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0106_01D2F8C0.746D5FE0" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQDLwAQokRlBJPELMGQUZlgB5WvpCAKEBN4FARkOuGoBlz6ZQAHgRoQEAVA5yDICOobcmAKaqpnUAhKQDEUCokCNmQHrKRtNo7sNGtA= Content-Language: de archived-at: Sun, 09 Jul 2017 12:34:31 -0000 This is a multipart message in MIME format. ------=_NextPart_000_0106_01D2F8C0.746D5FE0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi, =20 Here is my proposal: =20 https://github.com/apache/groovy/compare/master...uschindler:java9/module= Check =20 This only calls setAccessible, if the module of the class is open to = Groovy=E2=80=99s module and package. =20 This no longer prints any warning, but now it has the following problem = =E2=80=93 which is horrible to me, why does Groovy try to do this? =20 WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by = org.codehaus.groovy.vmplugin.v7.Java7$1 (=E2=80=A6) to constructor = java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int) WARNING: Please consider reporting this to the maintainers of = org.codehaus.groovy.vmplugin.v7.Java7$1 WARNING: Use --illegal-access=3Dwarn to enable warnings of further = illegal reflective access operations WARNING: All illegal access operations will be denied in a future = release =20 I also get a =E2=80=9Cstream closed=E2=80=9D error while trying to = =E2=80=9Ccompile-groovy=E2=80=9D ant task (I think that=E2=80=99s = related to the above). =20 Uwe =20 ----- Uwe Schindler uschindler@apache.org=20 ASF Member, Apache Lucene PMC / Committer Bremen, Germany http://lucene.apache.org/ =20 From: Uwe Schindler [mailto:uschindler@apache.org]=20 Sent: Sunday, July 9, 2017 1:13 PM To: dev@groovy.apache.org Subject: RE: trySetAccessible for Java 9 =20 Hi, =20 thanks for the insight. I was just not sure where this synthetic class = name came from. =20 I think we should ask on the Jigsaw mailing list if the warning was = intended to be also printed by the trySetAccessible call. IMHO, = trySetAccessible is a new API, so it should *not* grant access nor print = a warning. The Jigsaw kill switch should have no effect on = trySetAccessible! In contrast, setAccessible should behave as it does = with the Jigsaw kill switch enabled. =20 Nevertheless, I=E2=80=99d change the code in the following way: Instead = of trySetAccessible method handle, use a methodhandle to get the Module = instance of the Groovy runtime (fetch it once in the static initializer = -- should be the unnamed module, but we should be flexible here) and = when trying to make everything accessible in a class, use the same = methodhandle to get the module, too. If the module if different, = don=E2=80=99t try to make anything accessible at all and just return = with empty array. In the future we may try improve the whole thing my = looking into the module properties (=E2=80=9Copen=E2=80=9D packages), = but as a quick fix this is fine. =20 I will modify my patch proposal to do this. =20 Finally I have the question: Is it really needed to keep trying to make = everything accessible by default in Groovy 3 ??? Maybe you should break = backwards compatibility and no longer do this by default. This was IMHO = a mis-design of the Groovy language from the beginning. This is also a = security issue, as every groovy module can corrupt the whole JVM. This = is also one reason why Elasticsearch moved to their own scripting = language, as the cowboy =E2=80=9CsetAccessible=E2=80=9D everywhere is a = serious security issue! =20 Uwe =20 ----- Uwe Schindler uschindler@apache.org =20 ASF Member, Apache Lucene PMC / Committer Bremen, Germany http://lucene.apache.org/ =20 From: John Wagenleitner [mailto:john.wagenleitner@gmail.com]=20 Sent: Saturday, July 8, 2017 10:40 PM To: dev@groovy.apache.org =20 Subject: Re: trySetAccessible for Java 9 =20 Looks like the InjectedInvoker [1] is an implementation detail of the MH = lookup, probably used to allow calling the caller sensitive method. I = did not think that trySetAccessible prevents the message from appearing, = so even using that new method wont get rid of the warning even with the = default of --illegal-access=3Dpermit. If a direct call or reflection is = used instead of a MethodHandle it still prints the warning for the class = where the direct call or reflective call is made. =20 So semantically, as C=C3=A9dric mentioned, that new method may make = sense to use but it doesn't seem that it would eliminate the warning as = far as I can see. =20 [1] = http://hg.openjdk.java.net/jigsaw/jake/jdk/file/f140e400a7f0/src/java.bas= e/share/classes/java/lang/invoke/MethodHandleImpl.java#l1167 =20 On Wed, Jul 5, 2017 at 2:02 PM, Uwe Schindler > wrote: Hi, =20 unfortunately the MethodHandle approach did not work without a small = modification: =20 java.lang.IllegalAccessException: Attempt to lookup caller-sensitive = method using restricted lookup object =20 As the trySetAccessible method is caller sensitive, you cannot get a = MethodHandle from it using a public lookup. By changing the code to use = a normal (private) lookup, it works (as expected). There are no security = implications by that as we only access public methods. Only the lookup = object needs the =E2=80=9Cowner=E2=80=9D class to inject right caller = sensitiveness. The private lookup (private to CachedClass) is allowed to = get the method handle (and it should also be kept private inside = CachedClass, otherwise you violate security!!!) =20 I updated by branch: https://github.com/apache/groovy/compare/master...uschindler:java9/trySet= Accessible =20 This already helps when starting gradle, because as soon as the = compileGroovy tasks are starting, you are using the bootstrapped JAR = file. The CachedClass problem is fixed, no more illegal reflective = acceses, but I got a new one from a bytecode generated class (!?): =20 WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by = org.codehaus.groovy.reflection.InjectedInvoker/1364880320 = (file:/C:/Users/Uwe%20Schindler/Projects/groovy/target/classes/java/main/= ) to method java.lang.Object.finalize() WARNING: Please consider reporting this to the maintainers of = org.codehaus.groovy.reflection.InjectedInvoker/1364880320 WARNING: Use --illegal-access=3Dwarn to enable warnings of further = illegal reflective access operations WARNING: All illegal access operations will be denied in a future = release =20 As you see the whole thing got better, but now we have the same problem = in org.codehaus.groovy.reflection.InjectedInvoker, but this one is = synthetic. It looks like we must change the bytecode of that, too. But = here we are lucky: We can use the detected Java 9 version and just = create different bytecode at runtime depending on Java version? I have = not looked at this, I just verified that my branch works with Java 9 = build 175. =20 I have not looked at VMPlugin stuff, that should be done by somebody = else. But in that case: how about using a multi-release jar in that = case? I know there is no support to create those in Maven/Gradle, but I = am sure one can script it! =20 IMHO: I would on Java 9 never ever use the array setAccessible method. = You can be sure that it throws an exception in most cases, so why even = try and take the cost of =20 And I am not sure if setAccessible with array will not also print = warnings, once Alan Bateman & Co. fixed this bug (it is a bug)! =20 Uwe =20 ----- Uwe Schindler uschindler@apache.org =20 ASF Member, Apache Lucene PMC / Committer Bremen, Germany http://lucene.apache.org/ =20 From: C=C3=A9dric Champeau [mailto:cchampeau@apache.org = ]=20 Sent: Wednesday, July 5, 2017 8:12 PM To: Uwe Schindler = > Cc: dev@groovy.apache.org =20 Subject: Re: trySetAccessible for Java 9 =20 Thanks Uwe! To test with JDK 9 you'll need Gradle 4.1-milestone-1. I = know Jochen has some special setup to make it work on previous releases = of Gradle but I didn't try that. =20 2017-07-05 20:09 GMT+02:00 Uwe Schindler >: Here is my quick patch: = = https://github.com/apache/groovy/compare/master...uschindler:java9/trySet= Accessible =20 Sorry for my ignorance, but how to run tests with Java 9? Gradle fails = for me to launch daemon! =20 Uwe =20 ----- Uwe Schindler uschindler@apache.org =20 ASF Member, Apache Lucene PMC / Committer Bremen, Germany http://lucene.apache.org/ =20 From: Uwe Schindler [mailto:uschindler@apache.org = ]=20 Sent: Wednesday, July 5, 2017 7:27 PM To: dev@groovy.apache.org ; = cchampeau@apache.org =20 Subject: RE: trySetAccessible for Java 9 =20 Working on it. =20 I just looked at the code and found out that it already has a = =E2=80=9Efallback=E2=80=9C mechanism: It first tries = setAccessible(array, true) and then falls back to do it one by one. I = think with Java 9, wenn cannot do this. So I=E2=80=99d change that to: =20 * Get methodhandle in static initializer, if not there set to NULL * In the makeAccessible method check for nullness of methodhandle: if = null proceed as before, if not do a for-loop and call trySetAccesible() = on all, ignoring return value. =20 ----- Uwe Schindler uschindler@apache.org =20 ASF Member, Apache Lucene PMC / Committer Bremen, Germany http://lucene.apache.org/ =20 From: C=C3=A9dric Champeau [mailto:cchampeau@apache.org]=20 Sent: Wednesday, July 5, 2017 7:10 PM To: dev@groovy.apache.org =20 Cc: Russel Winder > Subject: Re: trySetAccessible for Java 9 =20 Thanks Uwe, patches/PRs are very welcome :) I did miss your suggestion, = sorry I wasn't able to follow everything on this list lately. =20 The risk I saw was that the MethodHandle class wasn't always available, = but for 2.4+, it's not a problem! =20 =20 2017-07-05 19:07 GMT+02:00 Uwe Schindler >: Hi, =20 I made this suggestion about a month ago! In Lucene/Elasticsearch we do = everything with MethodHandles that requires new Java 9 APIs (currently = Elasticsearch=E2=80=99s 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. =20 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. =20 I may provide a patch, if you like. I=E2=80=99d just need some = directions where to look at. Should be a 10 liner. =20 Uwe =20 ----- Uwe Schindler uschindler@apache.org =20 ASF Member, Apache Lucene PMC / Committer Bremen, Germany http://lucene.apache.org/ =20 From: C=C3=A9dric Champeau [mailto:cchampeau@apache.org = ]=20 Sent: Wednesday, July 5, 2017 6:55 PM To: Russel Winder > Cc: dev@groovy.apache.org =20 Subject: Re: trySetAccessible for Java 9 =20 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. =20 =20 =20 2017-07-05 18:41 GMT+02:00 Russel Winder >: On Wed, 2017-07-05 at 18:28 +0200, C=C3=A9dric Champeau wrote: > [=E2=80=A6] > 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. -- Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t:+44 20 7585 2200 = voip:sip: russel.winder@ekiga.net =20 41 Buckmaster Road m:+44 7770 465 077 = xmpp:russel@winder.org.uk =20 London SW11 1EN, UK w: www.russel.org.uk = skype:russel_winder =20 =20 =20 =20 ------=_NextPart_000_0106_01D2F8C0.746D5FE0 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable

Hi,

 

Here is my = proposal:

 

https://github.com/apache/groovy/compare/master...uschindl= er:java9/moduleCheck

 

This only calls setAccessible, if = the module of the class is open to Groovy=E2=80=99s module and = package.

 

This no longer prints any warning, = but now it has the following problem =E2=80=93 which is horrible to me, = why does Groovy try to do this?

 

WARNING: An illegal reflective = access operation has occurred

WARNING: Illegal reflective access = by org.codehaus.groovy.vmplugin.v7.Java7$1 (=E2=80=A6) to constructor = java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)

WARNING: Please consider reporting = this to the maintainers of = org.codehaus.groovy.vmplugin.v7.Java7$1

WARNING: Use = --illegal-access=3Dwarn to enable warnings of further illegal reflective = access operations

WARNING: All illegal = access operations will be denied in a future = release

 

I also get a =E2=80=9Cstream = closed=E2=80=9D error while trying to =E2=80=9Ccompile-groovy=E2=80=9D = ant task (I think that=E2=80=99s related to the = above).

 

Uwe

 

-----

Uwe = Schindler

uschindler@apache.org

ASF Member, Apache Lucene PMC / = Committer

Bremen, = Germany

http://lucene.apache.org/

 

From: Uwe = Schindler [mailto:uschindler@apache.org]
Sent: Sunday, July = 9, 2017 1:13 PM
To: dev@groovy.apache.org
Subject: = RE: trySetAccessible for Java 9

 

Hi,

 

thanks for the insight. I was just = not sure where this synthetic class name came = from.

 

I think we should ask on the Jigsaw = mailing list if the warning was intended to be also printed by the = trySetAccessible call. IMHO, trySetAccessible is a new API, so it should = *not* grant access nor print a warning. The Jigsaw kill switch = should have no effect on trySetAccessible! In contrast, setAccessible = should behave as it does with the Jigsaw kill switch = enabled.

 

Nevertheless, I=E2=80=99d change = the code in the following way: Instead of trySetAccessible method = handle, use a methodhandle to get the Module instance of the Groovy = runtime (fetch it once in the static initializer -- should be the = unnamed module, but we should be flexible here) and when trying to make = everything accessible in a class, use the same methodhandle to get the = module, too. If the module if different, don=E2=80=99t try to make = anything accessible at all and just return with empty array. In the = future we may try improve the whole thing my looking into the module = properties (=E2=80=9Copen=E2=80=9D packages), but as a quick fix this is = fine.

 

I will modify my patch proposal to = do this.

 

Finally I have the question: Is it = really needed to keep trying to make everything accessible by default in = Groovy 3 ??? Maybe you should break backwards compatibility and no = longer do this by default. This was IMHO a mis-design of the Groovy = language from the beginning. This is also a security issue, as every = groovy module can corrupt the whole JVM. This is also one reason why = Elasticsearch moved to their own scripting language, as the cowboy = =E2=80=9CsetAccessible=E2=80=9D everywhere is a serious security = issue!

 

Uwe

 

-----

Uwe = Schindler

uschindler@apache.org =

ASF = Member, Apache Lucene PMC / Committer

Bremen, Germany

http://lucene.apache.org/

 

From: John = Wagenleitner [mailto:john.wagenleitner@gmai= l.com]
Sent: Saturday, July 8, 2017 10:40 = PM
To: dev@groovy.apache.org
Sub= ject: Re: trySetAccessible for Java 9

 

Looks = like the InjectedInvoker [1] is an implementation detail of the MH = lookup, probably used to allow calling the caller sensitive = method.  I did not think that trySetAccessible prevents the message = from appearing, so even using that new method wont get rid of the = warning even with the default of --illegal-access=3Dpermit.  If a = direct call or reflection is used instead of a MethodHandle it still = prints the warning for the class where the direct call or reflective = call is made.

 

So semantically, as C=C3=A9dric mentioned, that = new method may make sense to use but it doesn't seem that it would = eliminate the warning as far as I can see.

 

 

On Wed, Jul 5, 2017 at 2:02 PM, Uwe Schindler <uschindler@apache.org> = wrote:

Hi,

 <= /o:p>

unfortunately the MethodHandle approach did not work = without a small modification:

 

java.lang.IllegalAccessException: Attempt to lookup = caller-sensitive method using restricted lookup = object

 

As the trySetAccessible method is caller sensitive, you = cannot get a MethodHandle from it using a public lookup. By changing the = code to use a normal (private) lookup, it works (as expected). There are = no security implications by that as we only access public methods. Only = the lookup object needs the =E2=80=9Cowner=E2=80=9D class to inject = right caller sensitiveness. The private lookup (private to CachedClass) = is allowed to get the method handle (and it should also be kept private = inside CachedClass, otherwise you violate = security!!!)

 

I updated by branch:

https://github.com/apache/groovy/compare/master...uschi= ndler:java9/trySetAccessible

 

This already helps when starting gradle, because as soon as = the compileGroovy tasks are starting, you are using the bootstrapped JAR = file. The CachedClass problem is fixed, no more illegal reflective = acceses, but I got a new one from a bytecode generated class = (!?):

 

WARNING: An illegal reflective access operation has = occurred

WARNING: Illegal reflective access by = org.codehaus.groovy.reflection.InjectedInvoker/1364880320 = (file:/C:/Users/Uwe%20Schindler/Projects/groovy/target/classes/java/main/= ) to method java.lang.Object.finalize()

WARNING: Please consider reporting this to the maintainers = of = org.codehaus.groovy.reflection.InjectedInvoker/1364880320

WARNING: Use --illegal-access=3Dwarn to enable warnings of = further illegal reflective access operations

WARNING: All illegal access operations will be denied in a = future release

 

As you see the whole thing got better, but now we have the = same problem in org.codehaus.groovy.reflection.InjectedInvoker, but this = one is synthetic. It looks like we must change the bytecode of that, = too. But here we are lucky: We can use the detected Java 9 version and = just create different bytecode at runtime depending on Java version? I = have not looked at this, I just verified that my branch works with Java = 9 build 175.

 

I have not looked at VMPlugin stuff, that should be done by = somebody else. But in that case: how about using a multi-release jar in = that case? I know there is no support to create those in Maven/Gradle, = but I am sure one can script it!

 

IMHO: I would on Java 9 never ever use the array = setAccessible method. You can be sure that it throws an exception in = most cases, so why even try and take the cost of

 

And I am not sure if setAccessible with array will not also = print warnings, once Alan Bateman & Co. fixed this bug (it is a = bug)!

 

Uwe

 

-----

Uwe Schindler

uschindler@apache.org

ASF Member, Apache Lucene PMC / = Committer

Bremen, = Germany

http://lucene.apache.org/

 <= /o:p>

From: C=C3=A9dric Champeau [mailto:cchampeau@apache.org]
Sent: = Wednesday, July 5, 2017 8:12 PM
To: Uwe Schindler <uschindler@apache.org>

<= p class=3DMsoNormal>
Cc: dev@groovy.apache.org
Subject: Re: = trySetAccessible for Java = 9

 <= /o:p>

Thanks Uwe! = To test with JDK 9 you'll need Gradle 4.1-milestone-1. I know Jochen has = some special setup to make it work on previous releases of Gradle but I = didn't try that.

 <= /o:p>

2017-07-05 = 20:09 GMT+02:00 Uwe Schindler <uschindler@apache.org>:

Here is my quick patch:

https://github.com/apache/groovy/compare/master...uschindler= :java9/trySetAccessible

 

Sorry for my ignorance, but how to run tests with Java 9? = Gradle fails for me to launch daemon!

 

Uwe

 

-----

Uwe Schindler

uschindler@apache.org

ASF Member, Apache Lucene PMC / = Committer

Bremen, = Germany

http://lucene.apache.org/

 <= /o:p>

From:= Uwe Schindler [mailto:uschindler@apache.org]
Sent: Wednesday, = July 5, 2017 7:27 PM
To: dev@groovy.apache.org; cchampeau@apache.org
Subject: RE: = trySetAccessible for Java 9

 <= /o:p>

Working on = it.

 <= /o:p>

I just looked at the code and found out that it already has = a =E2=80=9Efallback=E2=80=9C mechanism: It first tries = setAccessible(array, true) and then falls back to do it one by one. I = think with Java 9, wenn cannot do this. So I=E2=80=99d change that = to:

 

  • Get methodhandle in = static initializer, if not there set to NULL
  • In the makeAccessible = method check for nullness of methodhandle: if null proceed as before, if = not do a for-loop and call trySetAccesible() on all, ignoring return = value.

 

-----

Uwe Schindler

uschindler@apache.org

ASF Member, Apache Lucene PMC / = Committer

Bremen, = Germany

http://lucene.apache.org/

 <= /o:p>

From:= C=C3=A9dric Champeau [mailto:cchampeau@apache.org]
Sent: = Wednesday, July 5, 2017 7:10 PM
To: dev@groovy.apache.org
Cc: Russel Winder = <russel@winder.org.uk>
Subject: Re: = trySetAccessible for Java 9

 <= /o:p>

Thanks Uwe, = patches/PRs are very welcome :) I did miss your suggestion, sorry I = wasn't able to follow everything on this list = lately.

 <= /o:p>

The risk I = saw was that the MethodHandle class wasn't always available, but for = 2.4+, it's not a problem!

 <= /o:p>

 <= /o:p>

2017-07-05 = 19:07 GMT+02:00 Uwe Schindler <uschindler@apache.org>:

Hi,

 <= /o:p>

I made this suggestion about a month ago! In = Lucene/Elasticsearch we do everything with MethodHandles that requires = new Java 9 APIs (currently Elasticsearch=E2=80=99s 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=E2=80=99d just need = some directions where to look at. Should be a 10 = liner.

 

Uwe

 

-----

Uwe Schindler

uschindler@apache.org

ASF Member, Apache Lucene PMC / = Committer

Bremen, = Germany

http://lucene.apache.org/

 <= /o:p>

From:= C=C3=A9dric Champeau [mailto:cchampeau@apache.org]
Sent: Wednesday, = July 5, 2017 6:55 PM
To: Russel Winder <russel@winder.org.uk>
Cc: dev@groovy.apache.org
Subject: Re: = trySetAccessible for Java 9

 <= /o:p>

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.

 <= /o:p>

 <= /o:p>

 <= /o:p>

2017-07-05 = 18:41 GMT+02:00 Russel Winder <russel@winder.org.uk>:

On Wed, = 2017-07-05 at 18:28 +0200, C=C3=A9dric Champeau = wrote:
>
[=E2=80=A6]
> 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.

--
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D
Dr Russel Winder     t:+44 20 7585 = 2200   voip:sip:
russel.winder@ekiga.net
41 Buckmaster Road   m:+44 7770 465 = 077   xmpp:russel@winder.org.uk
London SW11 1EN, UK  w: www.russel.org.uk = skype:russel_winder

 <= /o:p>

 <= /o:p>

 <= /o:p>

 

------=_NextPart_000_0106_01D2F8C0.746D5FE0--