You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/08/19 07:01:53 UTC
[1/2] groovy git commit: GROOVY-7330: Incorrect dynamic proxy
creation from map when there are default methods (closes #785)
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_5_X dbb665df2 -> 4b4a286e0
GROOVY-7330: Incorrect dynamic proxy creation from map when there are default methods (closes #785)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/50256d86
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/50256d86
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/50256d86
Branch: refs/heads/GROOVY_2_5_X
Commit: 50256d86205932d4fbf6c7586d9eae7836d8dd85
Parents: dbb665d
Author: Paul King <pa...@asert.com.au>
Authored: Fri Aug 17 17:49:50 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Sun Aug 19 17:00:47 2018 +1000
----------------------------------------------------------------------
.../groovy/runtime/ConversionHandler.java | 10 ++--
.../runtime/InterfaceConversionMapTest.java | 54 ++++++++++++++++++++
2 files changed, 60 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/50256d86/src/main/java/org/codehaus/groovy/runtime/ConversionHandler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/ConversionHandler.java b/src/main/java/org/codehaus/groovy/runtime/ConversionHandler.java
index 8bf7c69..bed1a48 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ConversionHandler.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ConversionHandler.java
@@ -32,14 +32,12 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* This class is a general adapter to map a call to a Java interface
* to a given delegate.
- *
- * @author Ben Yu
- * @author <a href="mailto:blackdrag@gmx.org">Jochen Theodorou</a>
*/
public abstract class ConversionHandler implements InvocationHandler, Serializable {
private final Object delegate;
@@ -102,7 +100,7 @@ public abstract class ConversionHandler implements InvocationHandler, Serializab
* @see InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if (handleCache != null && isDefaultMethod(method)) {
+ if (handleCache != null && isDefaultMethod(method) && !defaultOverridden(method)) {
VMPlugin plugin = VMPluginFactory.getPlugin();
Object handle = handleCache.get(method);
if (handle == null) {
@@ -134,6 +132,10 @@ public abstract class ConversionHandler implements InvocationHandler, Serializab
}
}
+ private boolean defaultOverridden(Method method) {
+ return delegate instanceof Map && ((Map) delegate).containsKey(method.getName());
+ }
+
protected boolean isDefaultMethod(Method method) {
return ((method.getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) ==
Modifier.PUBLIC) && method.getDeclaringClass().isInterface();
http://git-wip-us.apache.org/repos/asf/groovy/blob/50256d86/src/test/org/codehaus/groovy/runtime/InterfaceConversionMapTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/InterfaceConversionMapTest.java b/src/test/org/codehaus/groovy/runtime/InterfaceConversionMapTest.java
new file mode 100644
index 0000000..5c67bd0
--- /dev/null
+++ b/src/test/org/codehaus/groovy/runtime/InterfaceConversionMapTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.runtime;
+
+import groovy.lang.GroovyShell;
+import org.codehaus.groovy.control.CompilerConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+
+public class InterfaceConversionMapTest {
+
+ private final GroovyShell shell;
+
+ public InterfaceConversionMapTest() {
+ final CompilerConfiguration cc = new CompilerConfiguration();
+ cc.setTargetBytecode(CompilerConfiguration.JDK8);
+ shell = new GroovyShell(cc);
+ }
+
+ // GROOVY-7330
+ @Test
+ public void testMapToProxy() {
+ final Map map = (Map) shell.evaluate("[x: {10}, y: {20}]");
+ final SomeInterface si = DefaultGroovyMethods.asType(map, SomeInterface.class);
+ Assert.assertEquals(20, si.y());
+ Assert.assertEquals(10, si.x());
+ }
+
+ public interface SomeInterface {
+ default int x() {
+ return 1;
+ }
+
+ int y();
+ }
+}
[2/2] groovy git commit: minor refactor
Posted by pa...@apache.org.
minor refactor
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4b4a286e
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4b4a286e
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4b4a286e
Branch: refs/heads/GROOVY_2_5_X
Commit: 4b4a286e0305de3e88cfbe86f796aa3ca5a1a621
Parents: 50256d8
Author: Paul King <pa...@asert.com.au>
Authored: Fri Aug 17 17:39:10 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Sun Aug 19 17:01:36 2018 +1000
----------------------------------------------------------------------
gradle/pomconfigurer.gradle | 3 +++
src/main/java/org/codehaus/groovy/runtime/ConvertedClosure.java | 4 ----
2 files changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/4b4a286e/gradle/pomconfigurer.gradle
----------------------------------------------------------------------
diff --git a/gradle/pomconfigurer.gradle b/gradle/pomconfigurer.gradle
index 68670f1..681b012 100644
--- a/gradle/pomconfigurer.gradle
+++ b/gradle/pomconfigurer.gradle
@@ -636,6 +636,9 @@ project.ext.pomConfigureClosureWithoutTweaks = {
contributor {
name 'Shruti Gupta'
}
+ contributor {
+ name 'Ben Yu'
+ }
}
mailingLists {
mailingList {
http://git-wip-us.apache.org/repos/asf/groovy/blob/4b4a286e/src/main/java/org/codehaus/groovy/runtime/ConvertedClosure.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/ConvertedClosure.java b/src/main/java/org/codehaus/groovy/runtime/ConvertedClosure.java
index dfc7ea0..84a627f 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ConvertedClosure.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ConvertedClosure.java
@@ -25,10 +25,6 @@ import java.lang.reflect.Method;
/**
* This class is a general adapter to adapt a closure to any Java interface.
- * <p>
- * @author Ben Yu
- * @author <a href="mailto:blackdrag@gmx.org">Jochen Theodorou</a>
- * Jul 27, 2006 3:50:51 PM
*/
public class ConvertedClosure extends ConversionHandler implements Serializable {
private final String methodName;