Hi Folks,

I am trying to control the behaviour exhibited by some of our POGOs when they are created using a Map constructor which contains keys that do NOT map to their properties e.g.

class Person {
  String name

def person = new Person([name: 'Edd', age: 35])

Normally the above would call propertyMissing() however I have discovered that I can define a trait (which the class then implements) and provide a default implementation of this method e.g.

trait LogsUnknownProperties implements GroovyInterceptable {

    private static final Logger LOGGER = Logger.getLogger(LogsUnknownProperties)

    def propertyMissing(String name, value){
        LOGGER.warn("Class: ${this.class.name} - Could not set property with name '${name}' having value '${value}' as property does not exist.")

This works brilliantly in mutable POGOs, however for POGOs which are annotated with @Immutable it doesn't work. From looking at the code in ImmutableASTTransformation.java this seems to be because the checkPropNames() method throws a MissingPropertyException:


Is there any way I can intercept the throwing of this exception so I can control the behaviour for @Immutable classes in the same way I can for mutable ones? I wondered if it could be achieved with a sprinkling of meta-programming but I'm not sure where to start looking?

Many thanks,