Skip to content

Commit

Permalink
Fix ClassCastException with overloaded setters if the metaclass overr…
Browse files Browse the repository at this point in the history
…ides a multisetter
  • Loading branch information
melix committed Nov 20, 2014
1 parent 7e918d1 commit 334325c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/groovy/lang/MetaClassImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,8 @@ public void addMetaBeanProperty(MetaBeanProperty mp) {
if (old != null) {
if (old instanceof MetaBeanProperty) {
field = ((MetaBeanProperty) old).getField();
} else if (old instanceof MultipleSetterProperty) {
field = ((MultipleSetterProperty)old).getField();
} else {
field = (CachedField) old;
}
Expand Down
17 changes: 16 additions & 1 deletion src/test/groovy/PropertyTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,22 @@ class PropertyTest extends GroovyTestCase {
assert a.x == "3"
'''
}


void testOverrideMultiSetterThroughMetaClass() {
assertScript '''
class A {
private String field
void setConstraints(Closure cl) {}
void setConstraints(String s) {}
String getField() { field }
}
A.metaClass.setConstraints = { delegate.field = it+it }
def a = new A()
a.constraints = '100'
assert a.field == '100100'
'''
}
}

class Base {
Expand Down

0 comments on commit 334325c

Please sign in to comment.