paulk-asert commented on a change in pull request #994: GROOVY-9075: The exception message should be more clear when a Groovy… URL: https://github.com/apache/groovy/pull/994#discussion_r314568581
########## File path: src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java ########## @@ -1016,4 +1018,21 @@ public static String convertPropertyName(String prop) { } return BeanUtils.decapitalize(prop); } + + // GROOVY-9075 + public static void checkMetaClassProperty(MetaClass oldValue, Object newValue) { + if (null == newValue) return; + + if (!(newValue instanceof MetaClass)) { + throw new IllegalArgumentException("the new metaClass[" + newValue.getClass() + "] is not an instance of " + MetaClass.class); + } + + MetaClass newMetaClass = (MetaClass) newValue; + if (!newMetaClass.getTheClass().isAssignableFrom(oldValue.getTheClass())) { Review comment: I am unsure that this is in fact the real requirement. The following currently works: ``` class MyMeta extends MetaClassImpl { MyMeta(Class klass) { super(klass) } } class S2 extends MetaClassImpl { S2(Class klass) { super(klass) } } def s1 = "foo${1+1}" def m1 = new MyMeta(GString) m1.initialize() s1.metaClass = m1 def s2 = 'bar' def m2 = new MyMeta(String) m2.initialize() s2.metaClass = m2 println m1.theClass.isAssignableFrom(m2.theClass) println m2.theClass.isAssignableFrom(m1.theClass) s1.metaClass = s2.metaClass ``` But wouldn't that now fail? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services