Skip to content

Fix ClassCastException in SensoryEventResponseHandler#1931

Merged
mltheuser merged 1 commit intomasterfrom
fix/transition-cast-error
Dec 11, 2025
Merged

Fix ClassCastException in SensoryEventResponseHandler#1931
mltheuser merged 1 commit intomasterfrom
fix/transition-cast-error

Conversation

@mltheuser
Copy link
Collaborator

🐛 Problem

A ClassCastException was thrown in production when the SensoryEventResponseHandler received a TransitionFailed event while awaiting a specific event via the NotifyOnEvent reaction.

Exception:

class com.ing.baker.runtime.akka.actor.process_instance.ProcessInstanceProtocol$TransitionFailed 
cannot be cast to class com.ing.baker.runtime.akka.actor.process_instance.ProcessInstanceProtocol$TransitionFired

🔍 Cause

In the streaming method, the guard condition for NotifyOnEvent blindly cast cache.head to TransitionFired without checking the actual type. When an interaction fails and a TransitionFailed event is added to the cache, the subsequent check causes a crash.

🛠️ Fix

Replaced the unsafe asInstanceOf cast with pattern matching that safely handles both TransitionFired and TransitionFailed events.

Before (Unsafe)

if (Option(cache.head.asInstanceOf[TransitionFired].output.asInstanceOf[EventInstance]).exists(_.name == onEvent))

After (Safe)

if (cache.head match {
  case fired: TransitionFired => Option(fired.output).collect { case e: EventInstance => e }.exists(_.name == onEvent)
  case _ => false
})

🧪 Testing

  • Added a regression test that verifies TransitionFailed events are handled gracefully without crashing the handler.

@mltheuser mltheuser force-pushed the fix/transition-cast-error branch from fda86e6 to c8eb47f Compare December 11, 2025 08:22
@mltheuser mltheuser merged commit 57f48b5 into master Dec 11, 2025
1 check passed
@mltheuser mltheuser deleted the fix/transition-cast-error branch December 11, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants