Skip to content

Commit 8c58c2e

Browse files
authored
Enforce data binding to instance should not affect static properties (#12665)
1 parent 0f0d702 commit 8c58c2e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

grails-databinding/src/main/groovy/grails/databinding/SimpleDataBinder.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ class SimpleDataBinder implements DataBinder {
264264
}
265265

266266
protected boolean isOkToBind(MetaProperty property, List whitelist, List blacklist) {
267-
isOkToBind(property.name, whitelist, blacklist) && (property.type != null && !(ClassLoader.class.isAssignableFrom(property.type) || ProtectionDomain.class.isAssignableFrom(property.type)))
267+
isOkToBind(property.name, whitelist, blacklist) &&
268+
(property.type != null) &&
269+
!Modifier.isStatic(property.modifiers) &&
270+
!(ClassLoader.class.isAssignableFrom(property.type) || ProtectionDomain.class.isAssignableFrom(property.type))
268271
}
269272

270273
protected IndexedPropertyReferenceDescriptor getIndexedPropertyReferenceDescriptor(propName) {

grails-databinding/src/test/groovy/grails/databinding/SimpleDataBinderSpec.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,30 @@ class SimpleDataBinderSpec extends Specification {
644644
then:
645645
fromAbstractB.a.data == 'abc'
646646
}
647+
648+
void 'Test binding when property is static Object, it should not bind'() {
649+
given:
650+
def binder = new SimpleDataBinder()
651+
def widget = new Widget()
652+
653+
when:
654+
binder.bind widget, [objectStaticProp: 6174] as SimpleMapDataBindingSource
655+
656+
then:
657+
widget.objectStaticProp instanceof Closure
658+
}
659+
660+
void 'Test binding when property is static, it should not bind'() {
661+
given:
662+
def binder = new SimpleDataBinder()
663+
def widget = new Widget()
664+
665+
when:
666+
binder.bind widget, [stringStaticProp: 'abc'] as SimpleMapDataBindingSource
667+
668+
then:
669+
widget.stringStaticProp == 'unchanged'
670+
}
647671
}
648672

649673
class Factory {
@@ -673,6 +697,8 @@ class Widget {
673697
List<Integer> listOfIntegers = []
674698
List<Long> listOfLongs = []
675699
Set<Factory> factories
700+
static objectStaticProp = { -> 495 }
701+
static String stringStaticProp = 'unchanged'
676702
}
677703

678704
class Gadget extends Widget {

0 commit comments

Comments
 (0)