[ 
https://issues.apache.org/jira/browse/GROOVY-3299?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles closed GROOVY-3299.
-------------------------------
    Resolution: Information Provided

When a meta class is initialized, it indexes methods from its super classes and 
interfaces (as returned by {{CachedClass#getNewMetaMethods()}}).  A change to a 
super type meta class is not reflected in these indexes.

I tried not caching expando methods in 
{{MetaClassImpl#inheritInterfaceNewMetaMethods}}, but it broke a bunch of 
expando tests.  I also tried re-initializing meta classes in 
{{ExpandoMetaClass#performRegistryCallbacks}}, which worked somewhat.  But it 
did wipe out other expando methods.

Thus, as alluded to in GROOVY-3873, if you use "Type.metaClass.someMetaMethod = 
\{ -> ... \}", you need to reset meta classes via "SubType.setMetaClass(null)" 
or some other means.

You can scan for existing meta classes with 
{{org.codehaus.groovy.reflection.ClassInfo}}:
{code:groovy}
MetaClassRegistry registry = GroovySystem.getMetaClassRegistry()
Class superClass = SomeType // your type
ClassInfo.onAllClassInfo { info ->
  Class theClass = info.getTheClass()
  if (superClass != theClass  && superClass.isAssignableFrom(theClass)
      && info.getMetaClassForClass() != null) {
    registry.removeMetaClass(theClass)
  }
}
{code}


> Modifying meta-class has no effect in some cases
> ------------------------------------------------
>
>                 Key: GROOVY-3299
>                 URL: https://issues.apache.org/jira/browse/GROOVY-3299
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 1.6-rc-1
>            Reporter: Peter Ledbrook
>            Assignee: Eric Milles
>            Priority: Major
>         Attachments: MetaClassCachingBugTests.groovy, 
> MetaClassCachingBugWithInterfaceTests.groovy
>
>
> See the attach test case. Basically it seems that the meta class for a class 
> is cached, but if it is modified (for example via EMC syntax), the cached 
> version is not updated.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to