2 Replies Latest reply on Feb 13, 2014 11:15 AM by Titu Petrea

    Problem compiling package, no valid constructor

    Jose Miguel Loor Apprentice

      Hi

       

      I am trying to compile a package, the validation passes but the compilation gives me this error:

       

      java.io.InvalidClassException: org.drools.base.field.ClassFieldImpl; org.drools.base.field.ClassFieldImpl; no valid constructor

       

      I am attaching the source drl file and java classes

       

      Thanks

        • 1. Re: Problem compiling package, no valid constructor
          Titu Petrea Newbie

          Hello,

           

          I have the same problem with drools 5.6.0.FINAL

           

          This is the code

          public class KnowledgeBaseSerializationTest

          {

           

              @Test

              public void test() throws IOException, ClassNotFoundException

              {

                  KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();

                  kb.add(ResourceFactory.newClassPathResource("drools/ActorEvent.drl"), ResourceType.DRL);

                  kb.add(ResourceFactory.newClassPathResource("drools/Authorization.drl"), ResourceType.DRL);

                  kb.add(ResourceFactory.newClassPathResource("drools/ConnectionAuthorizationReq.drl"), ResourceType.DRL);

                  kb.add(ResourceFactory.newClassPathResource("drools/StatusUpdateEvt.drl"), ResourceType.DRL);

                  kb.add(ResourceFactory.newClassPathResource("drools/Repository.drl"), ResourceType.DRL);

                  if (kb.hasErrors())

                  {

                      for (KnowledgeBuilderError err : kb.getErrors())

                      {

                          System.out.println(err.getLines() + " " + err.getMessage());

                      }

                      throw new IllegalStateException("DRL errors");

                  }

           

                  KnowledgeBase wroteKnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();

                  wroteKnowledgeBase.addKnowledgePackages(kb.getKnowledgePackages());

                  File file = new File("target/serializedKnowledgeBase");

           

                  // serialize KnowledgeBase

                  try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)))

                  {

                      oos.writeObject(wroteKnowledgeBase);

                      oos.flush();

                  }

           

                  // deserialize KnowledgeBase

                  ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));

                  KnowledgeBase readKnowledgeBase = (KnowledgeBase) ois.readObject();

              }

          }

           

          and the stacktrace:

           

          java.io.InvalidClassException: org.drools.base.field.ClassFieldImpl; no valid constructor

              at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:147)

              at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:755)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at org.drools.rule.constraint.MvelConstraint.readExternal(MvelConstraint.java:479)

              at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at java.util.ArrayList.readObject(ArrayList.java:733)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

              at java.lang.reflect.Method.invoke(Method.java:601)

              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)

              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at org.drools.rule.Pattern.readExternal(Pattern.java:125)

              at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at java.util.ArrayList.readObject(ArrayList.java:733)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

              at java.lang.reflect.Method.invoke(Method.java:601)

              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)

              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at org.drools.rule.GroupElement.readExternal(GroupElement.java:63)

              at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at org.drools.rule.Rule.readExternal(Rule.java:186)

              at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at org.drools.rule.JavaDialectRuntimeData.readExternal(JavaDialectRuntimeData.java:196)

              at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at java.util.HashMap.readObject(HashMap.java:1043)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

              at java.lang.reflect.Method.invoke(Method.java:601)

              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)

              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at org.drools.rule.DialectRuntimeRegistry.readExternal(DialectRuntimeRegistry.java:58)

              at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at org.drools.rule.Package.readExternal(Package.java:212)

              at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at java.util.HashMap.readObject(HashMap.java:1043)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

              at java.lang.reflect.Method.invoke(Method.java:601)

              at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)

              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at org.drools.common.AbstractRuleBase.readExternal(AbstractRuleBase.java:304)

              at org.drools.reteoo.ReteooRuleBase.readExternal(ReteooRuleBase.java:226)

              at org.drools.impl.KnowledgeBaseImpl.readExternal(KnowledgeBaseImpl.java:121)

              at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)

              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)

              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)

              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)

              at com.keba.kemove.cpm.drools.KnowledgeBaseSerializationTest.test(KnowledgeBaseSerializationTest.java:56)

           

          The exception is thrown at deserialization

          • 2. Re: Problem compiling package, no valid constructor
            Titu Petrea Newbie

            The problem is my case was that I had a condition like this:

            $processEntry: ProcessEntry

                (

                    rcvdMessage.extensionClass == Messages.StatusUpdateEvt.class &&

                    ((StatusUpdateEvt)rcvdMessage.expectExtension(Messages.StatusUpdateEvt.class)).status.wallboxPlugStatus.vehiclePlugged == true

                )

             

            extensionClass on attribute rcvdMessage is of type Class and when I serialized the KnowledgeBase, drools used the class org.drools.base.field.ClassFieldImpl.

            The solution was to write a method to test if extensionClass equals a Class (passed the class compared to as an argument):

             

            $processEntry: ProcessEntry

                (

                    rcvdMessage.isExtensionClass(Messages.StatusUpdateEvt.class) &&

                    ((StatusUpdateEvt)rcvdMessage.expectExtension(Messages.StatusUpdateEvt.class)).status.wallboxPlugStatus.vehiclePlugged == true

                )

             

            public boolean isExtensionClass(Class cls)

            {

                 return cls.equals(extensionClass);

            }