[
https://jira.jboss.org/browse/JBRULES-2722?page=com.atlassian.jira.plugin...
]
Nicolas Loriente updated JBRULES-2722:
--------------------------------------
Summary: VariablePersistenceStrategy does not pick up the correct VariablePersister
(was: Bug in VariablePersistenceStrategy when chosing a Variable Persister)
VariablePersistenceStrategy does not pick up the correct
VariablePersister
--------------------------------------------------------------------------
Key: JBRULES-2722
URL:
https://jira.jboss.org/browse/JBRULES-2722
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: All
Affects Versions: 5.1.1.FINAL
Reporter: Nicolas Loriente
Assignee: Mark Proctor
Attachments: missing-variable-persister-test.zip
Original Estimate: 1 hour
Remaining Estimate: 1 hour
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
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira