Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE on trait with implicit null #1942

Merged
merged 1 commit into from
Aug 22, 2023

Conversation

srchase
Copy link
Contributor

@srchase srchase commented Aug 22, 2023

This PR fixes smithy-syntax throwing a NullPointerException when encountering a trait with an implicit null.

Following this fix, if a trait is encountered with an empty body, the parentheses will be omitted.

This:

structure Struct {
    @default()
    a: String

    @default( )
    b: String

    @default(null)
    c: String
}

Will now be formatted to this:

structure Struct {
    @default
    a: String

    @default
    b: String

    @default(null)
    c: String
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@srchase srchase requested a review from a team as a code owner August 22, 2023 15:25
@mtdowling
Copy link
Member

$version: "2"
namespace smithy.example

@trait
structure foo {}

@foo
string MyString1

@foo()
string MyString2

@foo(null)
string MyString3

Results in:

──  ERROR  ────────────────────────────────────────────────────────── TraitValue
Shape: smithy.example#MyString3
File:  b.smithy:13:1

13| @foo(null)
  | ^
14| string MyString3

Error validating trait smithy.example#foo: Expected object value for structure
shape, smithy.example#foo; found null value

I think the only reliable approach is to omit () in the formatter:

@foo()

Becomes

@foo

Copy link
Member

@mtdowling mtdowling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment about this creating invalid models

@srchase srchase merged commit f16d587 into smithy-lang:main Aug 22, 2023
10 checks passed
@srchase srchase deleted the fix_null_trait_npe branch August 22, 2023 23:10
alextwoods pushed a commit to alextwoods/smithy that referenced this pull request Sep 15, 2023
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.

4 participants