I have been able to trace this failure to a defect in Groovy when calling the MetaClassRegistry.removeMetaClass() method. The root cause is that calls to MetaClassRegistry.removeMetaClass() can cause unexpected classes to be effectively removed from the MetaClassRegistry. See GROOVY-3623 for more details.
This defect manifests itself when the DefaultGrailsPluginManager calls its doDynamicMethods() method at start up. Prior to calling each plugins' doWithDynamicMethods() method (e.g. injecting the log property in the LoggingGrailsPlugin), a call to MetaClassRegistry.removeMetaClass() is made for each of the common Java classes:
public void doDynamicMethods() {
checkInitialised();
MetaClassRegistry registry = GroovySystem.getMetaClassRegistry();
for (int i = 0; i < COMMON_CLASSES.length; i++) {
Class commonClass = COMMON_CLASSES[i];
registry.removeMetaClass(commonClass);
}
for (Iterator i = pluginList.iterator(); i.hasNext();) {
GrailsPlugin plugin = (GrailsPlugin) i.next();
plugin.doWithDynamicMethods(applicationContext);
}
}
Each call to MetaClassRegistry.removeMetaClass() carries the risk that one or more other MetaClass entries will become inaccessible. If this happens to one of the Grails Artefact beans, the MetaClass for those beans will not be updated with any dynamic methods added for their Class.
Here's what happens when the MissingPropertyException is thrown:
1. Grails application starts.
2. Spring beans are created for Grails artefacts. Metaclass es for those beans are automatically registered with the Groovy MetaClassRegistry.
3. DefaultGrailsPluginManager makes calls to MetaClassRegistry.removeMetaClass(), ends up removing the MetaClass entry for one of the beans (e.g. a Grails service, job, etc.) This is the true point of failure.
4. LoggingGrailsPlugin adds dynamic getLog method for each artefact Class. However, for the artefact Class that was accidentally removed in step 3, a new MetaClass is created and registered, different from the one referenced within the bean for that artefact. The new MetaClass is injected with getLog, the old one is not.
5. A reference to the bean's log property is made. The MetaClass for this bean has never been modified, so a MissingPropertyException is thrown.
The real solution to this problem is to incorporate a version of Groovy with this defect patched (patch just submitted.) To workaround this specific failure case, one could also modify the LoggingGrailsPlugin such that each artefact bean's MetaClass is injected with the getLog method, in addition to the Class. However, this would still leave you vulnerable to the other possible problems with dynamic method injection caused by GROOVY-3623 .
Please attach an example application that reproduces the problem