This is an automated email from the ASF dual-hosted git repository.
emilles 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 5750f2cd0a GROOVY-11367, GROOVY-11369, GROOVY-11507: "class" and
"empty" properties
5750f2cd0a is described below
commit 5750f2cd0a25ac26c22ed4b33b1f6600d85bac5d
Author: Eric Milles <[email protected]>
AuthorDate: Sun Oct 20 11:26:05 2024 -0500
GROOVY-11367, GROOVY-11369, GROOVY-11507: "class" and "empty" properties
---
src/main/java/groovy/lang/MetaClassImpl.java | 6 ++++--
.../transform/stc/FieldsAndPropertiesSTCTest.groovy | 16 ++++++++++------
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/main/java/groovy/lang/MetaClassImpl.java
b/src/main/java/groovy/lang/MetaClassImpl.java
index 91273c5e08..d483e3a9d3 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -2219,6 +2219,8 @@ public class MetaClassImpl implements MetaClass,
MutableMetaClass {
}
if (!getter && !setter) continue;
+ if (isMap && isSpecialProperty(mp.getName())) continue;
+
if (!permissivePropertyAccess) { // GROOVY-5169, GROOVY-9081,
GROOVY-9103
boolean getterAccessible =
canAccessLegally(getterMetaMethod);
boolean setterAccessible =
canAccessLegally(setterMetaMethod);
@@ -2330,7 +2332,7 @@ public class MetaClassImpl implements MetaClass,
MutableMetaClass {
*
* @param propertyDescriptors the property descriptors
*/
- private void setupProperties(final PropertyDescriptor[]
propertyDescriptors) {
+ private void setUpProperties(final PropertyDescriptor[]
propertyDescriptors) {
if (theCachedClass.isInterface) {
CachedClass superClass = ReflectionCache.OBJECT_CLASS;
List<CachedClass> superInterfaces = new
ArrayList<>(theCachedClass.getInterfaces());
@@ -3382,7 +3384,7 @@ public class MetaClassImpl implements MetaClass,
MutableMetaClass {
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
// build up the metaproperties based on the public fields, property
descriptors,
// and the getters and setters
- setupProperties(descriptors);
+ setUpProperties(descriptors);
addRecordProperties(info);
EventSetDescriptor[] eventDescriptors = info.getEventSetDescriptors();
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index 03e27c8ea2..f3e749714d 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -669,12 +669,6 @@ class FieldsAndPropertiesSTCTest extends
StaticTypeCheckingTestCase {
assert map.containsKey('class')
assert !map.containsKey('metaClass')
'''
- shouldFailWithMessages '''
- def map = [:]
- map.properties = null
- ''',
- 'Cannot set read-only property: properties'
-
assertScript '''
Map<String,Number> map = [:]
@@ -714,6 +708,16 @@ class FieldsAndPropertiesSTCTest extends
StaticTypeCheckingTestCase {
}
test( [:].withDefault{ 'entry' } )
'''
+ assertScript '''
+ def map = [:]
+ def set = map.properties.keySet()
+ assert
set.intersect(['class','empty','metaClass','properties']).isEmpty()
+ '''
+ shouldFailWithMessages '''
+ def map = [:]
+ map.properties = null
+ ''',
+ 'Cannot set read-only property: properties'
}
// GROOVY-8074