You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/06/19 09:12:33 UTC
[groovy] branch danielsun/tweak-build updated: Tweak `$getLookup`
generation
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch danielsun/tweak-build
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/danielsun/tweak-build by this push:
new 618f524 Tweak `$getLookup` generation
618f524 is described below
commit 618f5247d701ca6cb90978970cef095593655ba5
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jun 19 17:12:17 2021 +0800
Tweak `$getLookup` generation
---
.../org/apache/groovy/lang/GroovyObjectHelper.java | 6 ++-
.../org/codehaus/groovy/classgen/Verifier.java | 3 +-
.../codehaus/groovy/classgen/VerifierTest.groovy | 59 ++++++++++++++++++++++
3 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/groovy/lang/GroovyObjectHelper.java b/src/main/java/org/apache/groovy/lang/GroovyObjectHelper.java
index 059a2a4..1a23bf8 100644
--- a/src/main/java/org/apache/groovy/lang/GroovyObjectHelper.java
+++ b/src/main/java/org/apache/groovy/lang/GroovyObjectHelper.java
@@ -72,8 +72,12 @@ public class GroovyObjectHelper {
}
private static Lookup doLookup(Class<?> groovyObjectClass) {
+ return doLookup(groovyObjectClass, MethodHandles.lookup());
+ }
+
+ private static Lookup doLookup(Class<?> groovyObjectClass, Lookup caller) {
try {
- return (Lookup) MethodHandles.lookup()
+ return (Lookup) caller
.findStatic(groovyObjectClass, "$getLookup", MethodType.methodType(Lookup.class, EMPTY_CLASS_ARRAY))
.invokeExact();
} catch (Throwable throwable) {
diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index f454ee7..0c559ef 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -76,6 +76,7 @@ import org.objectweb.asm.Opcodes;
import java.beans.Transient;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -360,7 +361,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
private void addGetLookupMethod(final ClassNode node) {
int modifiers = ACC_PUBLIC;
- boolean nonStaticInnerClass = null != node.getOuterClass() && !node.isStaticClass();
+ boolean nonStaticInnerClass = null != node.getOuterClass() && !Modifier.isStatic(node.getModifiers());
if (!nonStaticInnerClass) {
// static method cannot be declared in non-static inner class util Java 16
modifiers |= ACC_STATIC;
diff --git a/src/test/org/codehaus/groovy/classgen/VerifierTest.groovy b/src/test/org/codehaus/groovy/classgen/VerifierTest.groovy
new file mode 100644
index 0000000..ff0a6e2
--- /dev/null
+++ b/src/test/org/codehaus/groovy/classgen/VerifierTest.groovy
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.classgen
+
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+class VerifierTest {
+ @Test
+ void testGenGetLookupMethod() {
+ assertScript '''
+ import java.lang.reflect.Modifier
+ class Outer {
+ static class StaticInner {}
+ class Inner {}
+ }
+
+ {
+ def getLookupMethod = Outer.getDeclaredMethods().grep(m -> '$getLookup' == m.name)[0]
+ def modifiers = getLookupMethod.getModifiers()
+ assert Modifier.isPublic(modifiers)
+ assert Modifier.isStatic(modifiers)
+ }
+
+ {
+ def getLookupMethod = Outer.StaticInner.getDeclaredMethods().grep(m -> '$getLookup' == m.name)[0]
+ def modifiers = getLookupMethod.getModifiers()
+ assert Modifier.isPublic(modifiers)
+ assert Modifier.isStatic(modifiers)
+ }
+
+ {
+ def getLookupMethod = Outer.Inner.getDeclaredMethods().grep(m -> '$getLookup' == m.name)[0]
+ def modifiers = getLookupMethod.getModifiers()
+ assert Modifier.isPublic(modifiers)
+ assert !Modifier.isStatic(modifiers)
+ }
+ '''
+ }
+
+}