spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.54k stars 607 forks source link

IndexOutOfBoundsException when restoring form the database #1057

Open AbstractAlao opened 2 years ago

AbstractAlao commented 2 years ago

I am adding items to the extended state like so:

public void updateLoanProcessor(StateMachine<LoanEventStatus, LoanEventAction> stateMachine, LoanProcessor processor) {
        stateMachine.getExtendedState().getVariables().put(StateManager.PARAM_PROCESSOR, processor);
    }

When I reboot my service and try to acquire the state machine, I get the following error:


2022-07-19 19:23:43.645 ERROR [ycap-annuity-eligibility,,] 3144 --- [http-nio-8888-exec-340] o.s.s.s.DefaultStateMachineService       : Error handling context
--
 
com.esotericsoftware.kryo.KryoException: java.lang.IndexOutOfBoundsException: Index 2020 out of bounds for length 58
Serialization trace:
firstPaymentDate (org.yretirement.ycap.loan.repository.client.model.LoanApplicationForm)
loanApplication (org.yretirement.ycap.engine.client.model.LoanProcessor)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:144) ~[kryo-shaded-4.0.2.jar:na]
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:543) ~[kryo-shaded-4.0.2.jar:na]
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731) ~[kryo-shaded-4.0.2.jar:na]
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125) ~[kryo-shaded-4.0.2.jar:na]
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:543) ~[kryo-shaded-4.0.2.jar:na]
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:813) ~[kryo-shaded-4.0.2.jar:na]
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:161) ~[kryo-shaded-4.0.2.jar:na]
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:39) ~[kryo-shaded-4.0.2.jar:na]
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:813) ~[kryo-shaded-4.0.2.jar:na]
at org.springframework.statemachine.kryo.StateMachineContextSerializer.read(StateMachineContextSerializer.java:66) ~[spring-statemachine-kryo-3.0.0.jar:3.0.0]
at org.springframework.statemachine.kryo.StateMachineContextSerializer.read(StateMachineContextSerializer.java:39) ~[spring-statemachine-kryo-3.0.0.jar:3.0.0]
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:709) ~[kryo-shaded-4.0.2.jar:na]
at org.springframework.statemachine.kryo.KryoStateMachineSerialisationService.doDecode(KryoStateMachineSerialisationService.java:45) ~[spring-statemachine-kryo-3.0.0.jar:3.0.0]
at org.springframework.statemachine.kryo.AbstractKryoStateMachineSerialisationService$3.execute(AbstractKryoStateMachineSerialisationService.java:147) ~[spring-statemachine-kryo-3.0.0.jar:3.0.0]
at com.esotericsoftware.kryo.pool.KryoPoolQueueImpl.run(KryoPoolQueueImpl.java:58) ~[kryo-shaded-4.0.2.jar:na]
at org.springframework.statemachine.kryo.AbstractKryoStateMachineSerialisationService.decode(AbstractKryoStateMachineSerialisationService.java:143) ~[spring-statemachine-kryo-3.0.0.jar:3.0.0]
at org.springframework.statemachine.kryo.AbstractKryoStateMachineSerialisationService.decode(AbstractKryoStateMachineSerialisationService.java:130) ~[spring-statemachine-kryo-3.0.0.jar:3.0.0]
at org.springframework.statemachine.kryo.AbstractKryoStateMachineSerialisationService.deserialiseStateMachineContext(AbstractKryoStateMachineSerialisationService.java:72) ~[spring-statemachine-kryo-3.0.0.jar:3.0.0]
at org.springframework.statemachine.data.RepositoryStateMachinePersist.read(RepositoryStateMachinePersist.java:76) ~[spring-statemachine-data-common-3.0.0.jar:3.0.0]
at org.springframework.statemachine.data.jpa.JpaPersistingStateMachineInterceptor.read(JpaPersistingStateMachineInterceptor.java:70) ~[spring-statemachine-data-jpa-3.2.0.jar:3.2.0]
at org.springframework.statemachine.service.DefaultStateMachineService.acquireStateMachine(DefaultStateMachineService.java:94) ~[spring-statemachine-core-3.0.0.jar:3.0.0]
at org.springframework.statemachine.service.DefaultStateMachineService.acquireStateMachine(DefaultStateMachineService.java:79) ~[spring-statemachine-core-3.0.0.jar:3.0.0]
at org.yretirement.ycap.engine.api.service.LoanStateMachineService.retrieveStateMachine(LoanStateMachineService.java:343) ~[classes/:0.0.1-20220719.174449-63]

I'm not sure if it's because I added new properties to my class object.

gustavodaquino commented 1 year ago

Same issue here. I don't know if there is a most recent Kyro version to provide a better approach ignoring properties that don't exist in serialized data.