package org.drools.core;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.kie.api.runtime.ClassObjectFilter;
import org.kie.api.runtime.ObjectFilter;

@XmlRootElement(name="class-object-filter")
@XmlAccessorType(XmlAccessType.FIELD)
public class ClassObjectSerializationFilter implements ObjectFilter {

    @XmlAttribute(name="string",required=true)
    private String className = null;

    private transient Class filteredClass;

    public ClassObjectSerializationFilter() {
        // JAXB constructor
    }

    public ClassObjectSerializationFilter(Class clazz) {
        // use canonical name to avoid problems with anonymous classes
        this.className = clazz.getCanonicalName();
        this.filteredClass = clazz;
    }

    public ClassObjectSerializationFilter(ClassObjectFilter objectFilter) {
        this(objectFilter.getFilteredClass());
    }

    public Class getFilteredClass() {
        return filteredClass;
    }

    public void setFilteredClass(Class filteredClass) {
        this.filteredClass = filteredClass;
    }

    /**
     * @param object The object to be filtered
     * @return whether or not the Iterator accepts the given object according to its class.
     */
    @Override
    public boolean accept(Object object) {
        if( this.filteredClass == null ) {
            try {
                Class filteredClass = Class.forName(this.className);
                this.filteredClass = filteredClass;
            } catch( ClassNotFoundException e ) {
                throw new RuntimeException("Unable to instantiate filter class: " + e.getMessage(), e);
            }
        }
        return this.filteredClass.isAssignableFrom( object.getClass() );
    }
}

@@ -584,16 +584,62 @@
 Class;%0A%0A
+    private transient boolean skipLoadClass;%0A%0A
     publ
@@ -1471,15 +1471,29 @@
   if
+ 
 ( 
-this.
+!skipLoadClass && 
 filt
@@ -1548,22 +1548,16 @@
         
-Class 
 filtered
@@ -1599,60 +1599,8 @@
 e);%0A
-                this.filteredClass = filteredClass;%0A
     
@@ -1665,140 +1665,176 @@
     
-throw new RuntimeException(%22Unable to instantiate filter class: %22 + e.getMessage(), e);%0A            %7D%0A        %7D%0A        return this.
+skipLoadClass = true;%0A            %7D%0A        %7D%0A        return skipLoadClass ?%0A                className.equals( object.getClass().getCanonicalName() ) :%0A                
 filt

fix ClassObjectSerializationFilter