Skip to content

Commit d63c831

Browse files
committed
C#: Fix NPE in CSharpReceiver when receiving new DirectiveLine elements
The receiveList protocol creates objenesis instances (with null fields) for new ADD elements, so dl.getKind() can be null even when dl is not. Added null check for getKind() to match the existing dl != null guard.
1 parent 27c556e commit d63c831

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

rewrite-csharp/src/main/java/org/openrewrite/csharp/rpc/CSharpReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ public J visitConditionalDirective(Cs.ConditionalDirective conditionalDirective,
715715
List<Cs.DirectiveLine> directiveLines = q.receiveList(conditionalDirective.getDirectiveLines(), dl -> {
716716
int lineNumber = q.receive(dl != null ? dl.getLineNumber() : 0);
717717
String text = q.receive(dl != null ? dl.getText() : "");
718-
Cs.PreprocessorDirectiveKind kind = Cs.PreprocessorDirectiveKind.values()[q.receive(dl != null ? dl.getKind().ordinal() : 0)];
718+
Cs.PreprocessorDirectiveKind kind = Cs.PreprocessorDirectiveKind.values()[q.receive(dl != null && dl.getKind() != null ? dl.getKind().ordinal() : 0)];
719719
int groupId = q.receive(dl != null ? dl.getGroupId() : 0);
720720
int activeBranchIndex = q.receive(dl != null ? dl.getActiveBranchIndex() : -1);
721721
return new Cs.DirectiveLine(lineNumber, text, kind, groupId, activeBranchIndex);

0 commit comments

Comments
 (0)