groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] branch master updated: GROOVY-9217: Fix warning "An illegal reflective access operation has occurred" when setting property
Date Sun, 11 Aug 2019 19:23:16 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new c533d76  GROOVY-9217: Fix warning "An illegal reflective access operation has occurred"
when setting property
c533d76 is described below

commit c533d7660a9f6d2f1e8071114f2f42407c60f1a5
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Mon Aug 12 02:05:44 2019 +0800

    GROOVY-9217: Fix warning "An illegal reflective access operation has occurred" when setting
property
---
 src/main/java/groovy/lang/MetaClassImpl.java      |  9 ++++---
 src/test/groovy/bugs/Groovy9217Bug.groovy         | 29 +++++++++++++++++++++++
 src/test/groovy/bugs/groovy9081/Groovy9081.groovy |  2 +-
 3 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 949279b..82fb16d 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -1922,7 +1922,8 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
             //----------------------------------------------------------------------
             // executing the getter method
             //----------------------------------------------------------------------
-            return method.doMethodInvoke(object, arguments);
+            MetaMethod transformedMetaMethod = CallSiteHelper.transformMetaMethod(this, method,
MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+            return transformedMetaMethod.doMethodInvoke(object, arguments);
         }
 
         //----------------------------------------------------------------------
@@ -2826,7 +2827,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         }
 
         //----------------------------------------------------------------------
-        // executing the getter method
+        // executing the setter method
         //----------------------------------------------------------------------
         if (method != null) {
             if (arguments.length == 1) {
@@ -2840,7 +2841,9 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                         method.getParameterTypes()[1].getTheClass());
                 arguments[1] = newValue;
             }
-            method.doMethodInvoke(object, arguments);
+
+            MetaMethod transformedMetaMethod = CallSiteHelper.transformMetaMethod(this, method,
MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+            transformedMetaMethod.doMethodInvoke(object, arguments);
             return;
         }
 
diff --git a/src/test/groovy/bugs/Groovy9217Bug.groovy b/src/test/groovy/bugs/Groovy9217Bug.groovy
new file mode 100644
index 0000000..3d11c93
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9217Bug.groovy
@@ -0,0 +1,29 @@
+/*
+ *  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 groovy.bugs
+
+// TODO add JVM option `--illegal-access=deny` when all warnings fixed
+class Groovy9217Bug extends GroovyTestCase {
+    void testSetProperty() {
+        HttpURLConnection conn = new URL('http://www.bing.com').openConnection() as HttpURLConnection
+        conn.requestMethod = 'HEAD'
+        assert 'HEAD' == conn.requestMethod
+        conn.disconnect()
+    }
+}
diff --git a/src/test/groovy/bugs/groovy9081/Groovy9081.groovy b/src/test/groovy/bugs/groovy9081/Groovy9081.groovy
index ccd31a1..0eb8666 100644
--- a/src/test/groovy/bugs/groovy9081/Groovy9081.groovy
+++ b/src/test/groovy/bugs/groovy9081/Groovy9081.groovy
@@ -55,7 +55,7 @@ final class Groovy9081 {
         assert f.name
     }
 
-    @Test @Ignore
+    @Test
     void testGetPropertiesOfObjects() {
         assert null != ''.properties
     }


Mime
View raw message