Skip to content

C#: Use list protocol for ExceptionFilteredTry catch filters in RPC#7080

Draft
knutwannheden wants to merge 7 commits intomainfrom
fix-rpc-newobj-markers-cast
Draft

C#: Use list protocol for ExceptionFilteredTry catch filters in RPC#7080
knutwannheden wants to merge 7 commits intomainfrom
fix-rpc-newobj-markers-cast

Conversation

@knutwannheden
Copy link
Contributor

Summary

  • ExceptionFilteredTry catch filters were sent/received using manual loops instead of getAndSendList/receiveList
  • When the C# receiver created a new shell via NewObj (e.g. after RPC restart), the shell's CatchFilters was empty, so the receiver consumed zero messages while the sender sent N — desynchronizing the stream
  • This caused InvalidCastException: Unable to cast JLeftPadded<object> to Markers when parsing files with catch ... when clauses
  • Fixed all four implementations (Java sender/receiver, C# sender/receiver) to use the list primitives

Test plan

  • Verified with a test that parses a file containing catch (Exception ex) when (...), shuts down RPC, and reprints — previously crashed, now passes
  • All existing CSharpRecipeTest tests pass

The catch filters in ExceptionFilteredTry were sent/received using
manual loops instead of the standard getAndSendList/receiveList
protocol. When the C# receiver created a new shell via NewObj (e.g.
after RPC restart), the shell's CatchFilters was an empty list, so
the receiver consumed zero messages while the sender had sent N filter
messages — desynchronizing the RPC stream and causing an
InvalidCastException (JLeftPadded<object> → Markers).

Fix all four implementations (Java sender/receiver, C# sender/receiver)
to use the list primitives which handle ADD/CHANGE/position-matching
correctly regardless of the before object's state.
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Mar 20, 2026
@knutwannheden knutwannheden changed the title Use list protocol for ExceptionFilteredTry catch filters in RPC C#: Use list protocol for ExceptionFilteredTry catch filters in RPC Mar 20, 2026
@knutwannheden knutwannheden marked this pull request as draft March 20, 2026 17:16
SendList now handles null elements (e.g. catch clauses without 'when'
filters) by sending a simple ADD with no value, which the receiver
interprets as null. Previously, null elements passed to Add() caused
ArgumentNullException at Reference.GetValueNonNull.
@knutwannheden knutwannheden force-pushed the fix-rpc-newobj-markers-cast branch from 6cc3025 to 33d6463 Compare March 20, 2026 17:16
Mirror of the C# fix — null list elements are sent as NO_CHANGE
to avoid NPE in add()/requireNonNull when lists contain null entries
(e.g. ExceptionFilteredTry catch filters without 'when' clauses).
Same fix as Java and C# — null list elements are sent as NO_CHANGE
to avoid errors when lists contain null entries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant