Skip to content

Commit

Permalink
Fix NPE on trait with implicit null
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase committed Aug 22, 2023
1 parent 68d122e commit 898dc09
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,23 +365,32 @@ private Doc visit(TreeCursor cursor) {
})
.build();
} else {
// Check the inner trait node for hard line breaks rather than the wrapper.
TreeCursor traitNode = cursor
.getFirstChild(TreeType.TRAIT_NODE)
.getFirstChild(TreeType.NODE_VALUE)
.getFirstChild(); // The actual node value.
return new BracketBuilder()
.open(Doc.text("("))
.close(Doc.text(")"))
.extractChildren(cursor, traitNode, child -> {
if (child.getTree().getType() == TreeType.TRAIT_NODE) {
// Split WS and NODE_VALUE so that they appear on different lines.
return child.getChildrenByType(TreeType.NODE_VALUE, TreeType.WS).stream();
} else {
return Stream.empty();
}
})
.build();
if (cursor.getFirstChild(TreeType.TRAIT_NODE) != null) {
// Check the inner trait node for hard line breaks rather than the wrapper.
TreeCursor traitNode = cursor
.getFirstChild(TreeType.TRAIT_NODE)
.getFirstChild(TreeType.NODE_VALUE)
.getFirstChild(); // The actual node value.
return new BracketBuilder()
.open(Doc.text("("))
.close(Doc.text(")"))
.extractChildren(cursor, traitNode, child -> {
if (child.getTree().getType() == TreeType.TRAIT_NODE) {
// Split WS and NODE_VALUE so that they appear on different lines.
return child.getChildrenByType(TreeType.NODE_VALUE, TreeType.WS).stream();
} else {
return Stream.empty();
}
})
.build();
} else {
// If the trait node is empty, explicitly set it to `null`.
return new BracketBuilder()
.open(Doc.text("("))
.close(Doc.text(")"))
.children(Stream.<Doc>builder().add(Doc.text("null")).build())
.build();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$version: "2.0"

namespace smithy.example

structure Struct {
@default(null)
a: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$version: "2.0"

namespace smithy.example

structure Struct {
@default()
a: String
}

0 comments on commit 898dc09

Please sign in to comment.