-
Notifications
You must be signed in to change notification settings - Fork 218
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
Mitigate possible NSE exception in PrivateAccessValidator.java #2015
Mitigate possible NSE exception in PrivateAccessValidator.java #2015
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this. Did you run into this issue in practice? By the time this validator is invoked, all model references have been validated. Given this, I think a more tactical fix is to change the call to .get() the neighbor to use expectNeighborShape instead. This way it throws a more useful error message and doesn’t need the extra complexity. See
smithy/smithy-model/src/main/java/software/amazon/smithy/model/neighbor/Relationship.java
Line 117 in 32ff2c3
public Shape expectNeighborShape() { |
Using `Relationship#expectNeighborShape` in place of the optional .get defined for `Relationship`.
Thanks for the review, @mtdowling; I didn't mean for you to look at this over the weekend, apologies. I haven't seen the error in-practice, but it was reported by a static analysis tool after I ran a compilation locally. I'm happy to help improve the codebase if this is something you would find useful. Are there any places in the code in particular that actually might be at risk of |
Thanks for updating. Generally any place that we use |
Got it, thanks! I'll fix the checkstyle errors shortly. |
Thanks! |
Issue #, if available: n/a
Description of changes:
Within
PrivateAccessValidator#getPrivateAccessValiationEvent
, an unchecked call toOptional#get
occurs. This might throw aNoSuchElementException
if the optional is indeed empty.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.