-
Bug
-
Resolution: Done
-
Major
-
5.5.0.Final
-
None
I'm using Drools 5.4.0 (but also tried it with the last release of Drools 5.5.0) to save the session state when the application server restarts / stops. Everything works fine and the session state is properly restored, but when new fact is inserted the following exception is thrown:
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.drools.reteoo.ReteooFactHandleFactory.newFactHandle(ReteooFactHandleFactory.java:57)
at org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:68)
at org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:53)
at org.drools.common.NamedEntryPoint.createHandle(NamedEntryPoint.java:745)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:287)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:888)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847)
at org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:269)
I explored through Drools code, and figured out time stamp extractor getExtractToClass method is evaluating to null (line 57 ReteooFactHandleFactory):
public final InternalFactHandle newFactHandle(final int id,
final Object object,
final long recency,
final ObjectTypeConf conf,
final InternalWorkingMemory workingMemory,
final WorkingMemoryEntryPoint wmEntryPoint) {
if ( conf != null && conf.isEvent() ) {
TypeDeclaration type = conf.getTypeDeclaration();
long timestamp;
if ( type.getTimestampExtractor() != null ) {
if ( Date.class.isAssignableFrom( type.getTimestampExtractor().getExtractToClass() ) )
else
{ timestamp = type.getTimestampExtractor().getLongValue( workingMemory, object ); } } else {
timestamp = workingMemory.getTimerService().getCurrentTime();
....
My code for storing / restoring session:
public void saveCorrelator(FileOutputStream output) throws IOException
{ DroolsObjectOutputStream droolsOut = new DroolsObjectOutputStream(output); droolsOut.writeObject(ksession.getKnowledgeBase()); Marshaller mas = createMarshaller(ksession.getKnowledgeBase()); mas.marshall(droolsOut, ksession); droolsOut.flush(); droolsOut.close(); } public void loadCorrelator(FileInputStream input) throws IOException,
ClassNotFoundException {
DroolsObjectInputStream droolsIn = new DroolsObjectInputStream(input, this.getClass().getClassLoader());
try
catch(EOFException e)
{ log.error("EOFException on correlator restore"); }finally
{ droolsIn.close(); }}
private Marshaller createMarshaller(KnowledgeBase kbase) {
ObjectMarshallingStrategyAcceptor acceptor = MarshallerFactory
.newClassFilterAcceptor(new String[]
);
ObjectMarshallingStrategy strategy = MarshallerFactory
.newSerializeMarshallingStrategy(acceptor);
return MarshallerFactory.newMarshaller(kbase,
new ObjectMarshallingStrategy[]
);
}