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 2020/07/04 17:19:47 UTC
[groovy] 01/02: GROOVY-9618: index "static getX()" as "X" if class
field X also exists
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch check-PR1296
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit d041b71fffbdbc2f1d8f26949c1510d137f54159
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Jul 3 09:58:04 2020 -0500
GROOVY-9618: index "static getX()" as "X" if class field X also exists
// one meta-property "X"
class C {
static private X
static getX()
}
// one meta-property "x"
class C {
static private x
static getX()
}
// one meta-property "x" and one meta-field "X"
class C {
static private x, X
static getX()
}
// one class meta-property "X" and one instance meta-field "x"
class C {
static private X
static getX()
private x
}
---
src/main/java/groovy/lang/MetaClassImpl.java | 15 ++++++----
src/test/groovy/bugs/Groovy9618.groovy | 45 ++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 5 deletions(-)
diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 63f95d3..2ada75c 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -2606,11 +2606,16 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
}
private static void createMetaBeanProperty(SingleKeyHashMap propertyIndex, String propName, boolean isGetter, MetaMethod propertyMethod) {
- // is this property already accounted for?
- MetaProperty mp = (MetaProperty) propertyIndex.get(propName);
- MetaProperty newMp = makeReplacementMetaProperty(mp, propName, isGetter, propertyMethod);
- if (newMp != mp) {
- propertyIndex.put(propName, newMp);
+ // check if property is already accounted for
+ MetaProperty oldMP = (MetaProperty) propertyIndex.get(propName);
+ if (oldMP == null && propName.length() == 1 && propertyMethod.isStatic()) {
+ oldMP = (MetaProperty) propertyIndex.get(propName.toUpperCase());
+ if (oldMP != null) propName = propName.toUpperCase();
+ }
+
+ MetaProperty newMP = makeReplacementMetaProperty(oldMP, propName, isGetter, propertyMethod);
+ if (newMP != oldMP) {
+ propertyIndex.put(propName, newMP);
}
}
diff --git a/src/test/groovy/bugs/Groovy9618.groovy b/src/test/groovy/bugs/Groovy9618.groovy
new file mode 100644
index 0000000..8fc5d31
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9618.groovy
@@ -0,0 +1,45 @@
+/*
+ * 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
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy9618 {
+
+ @Test
+ void testGetPropertyFromOuterClassOfSuper() {
+ assertScript '''
+ class A {
+ private static X = 1
+ static getX() { 2 }
+ static class B { }
+ }
+
+ class C extends A.B {
+ def m() {
+ return X
+ }
+ }
+
+ assert new C().m() == 2
+ '''
+ }
+}