groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Java 9 support?
Date Mon, 10 Sep 2018 20:04:52 GMT
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?

[1]
https://github.com/apache/groovy/blob/ac0e1d232f0612518a87ce2aa5e443e0975cb3f4/src/main/java/org/codehaus/groovy/vmplugin/v7/Java7.java#L40

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>

Mime
View raw message