Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-2722

VariablePersistenceStrategy does not pick up the correct VariablePersister

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    • Hide

      Run test VariablePersisterTest.java included in the attached project.

      Show
      Run test VariablePersisterTest.java included in the attached project.
    • Low

    Description

      drools-persistence-jpa-5.1.1 has a bug in VariablePersistenceStrategy.

      When looking at "interfaces" to find a Variable Persister Drools currently doesn't find the persister for classes that extend a variable persister type.

      e.g. java.language.Long which extends Number which implements Serializable. By inheritance Long is a Serializable and shold be persited with SerializableVariablePersister if the persister is registered.

      The following block of code is found in the class "org.drools.persistence.processinstance.VariablePersistenceStrategy" in the method "private String getVariablePersistenceType(Object o)":

      // at last for interfaces
      Class<?>[] interfaces = o.getClass().getInterfaces();
      if (interfaces != null) {
      for (Class<?> clazz : interfaces) {
      persisterFQN = types.get(clazz.getName());
      if (persisterFQN != null && !persisterFQN.equals(""))

      { return persisterFQN; }


      }
      }

      Problem:
      This approach works ONLY when the interfaces are implemented directly but does NOT work when there is inheritance because o.getClass().getInterfaces() returns only the interfaces the class "o" implements directly but does NOT return the interfaces it's parent (and parent's parent, etc) implement.

      For example in considering SerializableVariablePersister:

      it WILL work when having a Serializable in the form of:
      class DummySerializable implements Serializable

      {.....}

      But it will NOT work if the serializable is in the form of:
      class ChildDummySerializable extends DummySerializable {.....}

      It will neither for any class that participates in the hierarchy (e.g. GrandChildDummySerializable extends ChildDummySerializable

      {.....}

      , etc.)

      If the variable that doesn't implement the Variable Persisted Type directly it will NOT be persisted with the "expected" variable persister.

      Suggested Fix:

      Class<?> clazz = o.getClass();
      do {
      Class<?>[] interfaces = clazz.getInterfaces();
      for(Class<?> interfaze : interfaces) {
      persisterFQN = types.get(interfaze.getName());
      if (persisterFQN != null && !persisterFQN.equals(""))

      { System.out.println("Persistence strategy returns: " + persisterFQN); return persisterFQN; }


      }
      } while ( (clazz = clazz.getSuperclass() ) != null);

      The fix pointed above will walk through each class in the inheritance chain and will pull ALL interfaces until it finds one that is of a Variable Persisted Type and has a corresponding Variable Persister

      Attachments

        Activity

          People

            dlopezleon Diego Lopez Leon (Inactive)
            nicolas.loriente Nicolas Loriente (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

            Dates

              Created:
              Updated:
              Resolved:
              Archived:

              Time Tracking

                Estimated:
                Original Estimate - 1 hour
                1h
                Remaining:
                Remaining Estimate - 1 hour
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified

                PagerDuty