Java 9 support?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Java 9 support?

Romain Manni-Bucau
Hi guys,

I'm using gplus maven plugin and I get issues running on java 9:

Seems it leads to [1] which does not work on java > 8. A simple workaround can be to use privateLookupIn on java 9 (it is not available on java 8):

static {
Constructor<MethodHandles.Lookup> lookup = null;
Method privateLookup = null;
try { // java 9
privateLookup = MethodHandles.class.getMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
} catch (final NoSuchMethodException e) { // java 8
try {
lookup = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, Integer.TYPE);
if (!lookup.isAccessible()) {
lookup.setAccessible(true);
}
} catch (final NoSuchMethodException ex) {
throw new IllegalStateException("Incompatible JVM", e);
}
}
PRIVATE_LOOKUP = privateLookup;
LOOKUP = lookup;
}

public static MethodHandles.Lookup of(final Class<?> declaringClass) {
try {
if (PRIVATE_LOOKUP != null) {
return MethodHandles.Lookup.class
.cast(PRIVATE_LOOKUP.invoke(null, declaringClass, MethodHandles.lookup()));
}
return LOOKUP.newInstance(declaringClass, MethodHandles.Lookup.PRIVATE).in(declaringClass);
} catch (final IllegalAccessException | InstantiationException e) {
throw new IllegalArgumentException(e);
} catch (final InvocationTargetException e) {
throw toRuntimeException(e);
}
}


Any plan to release a j9/10/11 groovy version?

Reply | Threaded
Open this post in threaded view
|

Re: Java 9 support?

paulk_asert
Can you elaborate a bit more on the steps to get the error you are seeing?
We've mainly been using gradle on JDK11.

On Tue, Sep 11, 2018 at 6:05 AM Romain Manni-Bucau <[hidden email]> wrote:
Hi guys,

I'm using gplus maven plugin and I get issues running on java 9:

Seems it leads to [1] which does not work on java > 8. A simple workaround can be to use privateLookupIn on java 9 (it is not available on java 8):

static {
Constructor<MethodHandles.Lookup> lookup = null;
Method privateLookup = null;
try { // java 9
privateLookup = MethodHandles.class.getMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
} catch (final NoSuchMethodException e) { // java 8
try {
lookup = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, Integer.TYPE);
if (!lookup.isAccessible()) {
lookup.setAccessible(true);
}
} catch (final NoSuchMethodException ex) {
throw new IllegalStateException("Incompatible JVM", e);
}
}
PRIVATE_LOOKUP = privateLookup;
LOOKUP = lookup;
}

public static MethodHandles.Lookup of(final Class<?> declaringClass) {
try {
if (PRIVATE_LOOKUP != null) {
return MethodHandles.Lookup.class
.cast(PRIVATE_LOOKUP.invoke(null, declaringClass, MethodHandles.lookup()));
}
return LOOKUP.newInstance(declaringClass, MethodHandles.Lookup.PRIVATE).in(declaringClass);
} catch (final IllegalAccessException | InstantiationException e) {
throw new IllegalArgumentException(e);
} catch (final InvocationTargetException e) {
throw toRuntimeException(e);
}
}


Any plan to release a j9/10/11 groovy version?

Reply | Threaded
Open this post in threaded view
|

Re: Java 9 support?

Romain Manni-Bucau
Just trying to run some simple script in a maven build. Not sure what triggered VMPlugin loading but code doesnt handle j9 it seems.

My version is the last alpha of v3.

Can try to reproduce it tomorrow if it helps.

Le lun. 10 sept. 2018 23:17, Paul King <[hidden email]> a écrit :
Can you elaborate a bit more on the steps to get the error you are seeing?
We've mainly been using gradle on JDK11.

On Tue, Sep 11, 2018 at 6:05 AM Romain Manni-Bucau <[hidden email]> wrote:
Hi guys,

I'm using gplus maven plugin and I get issues running on java 9:

Seems it leads to [1] which does not work on java > 8. A simple workaround can be to use privateLookupIn on java 9 (it is not available on java 8):

static {
Constructor<MethodHandles.Lookup> lookup = null;
Method privateLookup = null;
try { // java 9
privateLookup = MethodHandles.class.getMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
} catch (final NoSuchMethodException e) { // java 8
try {
lookup = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, Integer.TYPE);
if (!lookup.isAccessible()) {
lookup.setAccessible(true);
}
} catch (final NoSuchMethodException ex) {
throw new IllegalStateException("Incompatible JVM", e);
}
}
PRIVATE_LOOKUP = privateLookup;
LOOKUP = lookup;
}

public static MethodHandles.Lookup of(final Class<?> declaringClass) {
try {
if (PRIVATE_LOOKUP != null) {
return MethodHandles.Lookup.class
.cast(PRIVATE_LOOKUP.invoke(null, declaringClass, MethodHandles.lookup()));
}
return LOOKUP.newInstance(declaringClass, MethodHandles.Lookup.PRIVATE).in(declaringClass);
} catch (final IllegalAccessException | InstantiationException e) {
throw new IllegalArgumentException(e);
} catch (final InvocationTargetException e) {
throw toRuntimeException(e);
}
}


Any plan to release a j9/10/11 groovy version?