[jboss-jira] [JBoss JIRA] (DROOLS-778) Deserialization error: java.io.InvalidClassException: org.drools.base.evaluators.StrEvaluatorDefinition$StrEvaluator; no valid constructor

Philip McWilliams (JIRA) issues at jboss.org
Fri May 1 12:05:45 EDT 2015


Philip McWilliams created DROOLS-778:
----------------------------------------

             Summary: Deserialization error: java.io.InvalidClassException: org.drools.base.evaluators.StrEvaluatorDefinition$StrEvaluator; no valid constructor 
                 Key: DROOLS-778
                 URL: https://issues.jboss.org/browse/DROOLS-778
             Project: Drools
          Issue Type: Bug
          Components: core engine
    Affects Versions: 5.5.0.Final
         Environment: Windows 7; Java 6; Drools 5.5.0.Final (incl. drools-core, drools-compiler, drools-spring and drools-camel)
            Reporter: Philip McWilliams
            Assignee: Mario Fusco


I am seeking to compile rules at build-time and then save (serialize) the output to disk.  At deployment, I then wish to build a knowledge base from the deserialized knowledge packages (rather than by re-compiling the source rules files).

In general this works ... unless I use the "str" operator in an LHS.  This operator is implemented by the *org.drools.base.evaluators.StrEvaluatorDefinition$StrEvaluator* class and this class does not appear to deserialize properly.

A round trip exercise on my local machine always fails with this error:
{code}
java.io.InvalidClassException: org.drools.base.evaluators.StrEvaluatorDefinition$StrEvaluator; org.drools.base.evaluators.StrEvaluatorDefinition$StrEvaluator; no valid constructor 
{code}

My serialization/deserialization code is standard ... to serialize:
{code}
    private void saveOutput(KnowledgeBuilder kbuilder) throws IOException {
        Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
        String outputFilename = outputFile == null ? "" : outputFile.trim();
        if (outputFilename.isEmpty()) {
            outputFilename = project.getBasedir() + "target/classes/drools.drlx";
        }
        ObjectOutputStream out = null;
        try {
            getLog().info("Saving compiled Drools output to " + outputFilename);
            out = new ObjectOutputStream(new FileOutputStream(outputFilename));
            out.writeObject(kpkgs);
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }
{code}
... to deserialize:
{code}
    private Collection<KnowledgePackage> deserializeKnowledgePackages(Resource[] knowledgePackageObjects) throws IOException, ClassNotFoundException {
        Collection<KnowledgePackage> knowledgePackages = new ArrayList<KnowledgePackage>();
        for (Resource knowledgePackageObject : knowledgePackageObjects) {
            LOG.info("Deserializing pre-compiled package " + knowledgePackageObject.getFilename());
            ObjectInputStream in = null;
            try {
                in = new ObjectInputStream(knowledgePackageObject.getInputStream());
                // The input stream might contain an individual package or a collection.
                knowledgePackages.addAll((Collection<KnowledgePackage>) in.readObject());
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        }
        return knowledgePackages;
    }
{code}

My workaround is to avoid using the "str" operator.

*Apologies*: I have *not* checked version 6.2.0.Final because I have not yet worked out what versions of the Drools Spring and Camel modules to use (for 5.5.0.Final they were all versioned identically).



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the jboss-jira mailing list