Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-778

Deserialization error: java.io.InvalidClassException: org.drools.base.evaluators.StrEvaluatorDefinition$StrEvaluator; no valid constructor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 6.0.0.Final
    • 5.5.0.Final
    • core engine
    • None

    Description

      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:

      java.io.InvalidClassException: org.drools.base.evaluators.StrEvaluatorDefinition$StrEvaluator; org.drools.base.evaluators.StrEvaluatorDefinition$StrEvaluator; no valid constructor 
      

      My serialization/deserialization code is standard ... to serialize:

          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();
                  }
              }
          }
      

      ... to deserialize:

          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;
          }
      

      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).

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            pmcwilli Philip McWilliams (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: