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

Mitigate possible NSE exception in PrivateAccessValidator.java #2015

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import software.amazon.smithy.model.neighbor.Relationship;
import software.amazon.smithy.model.neighbor.RelationshipType;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.PrivateTrait;
import software.amazon.smithy.model.validation.AbstractValidator;
import software.amazon.smithy.model.validation.ValidationEvent;
Expand All @@ -50,17 +51,18 @@ private void validateNeighbors(Shape shape, List<Relationship> relationships, Li
String namespace = shape.getId().getNamespace();
for (Relationship rel : relationships) {
if (!rel.getShape().getId().getNamespace().equals(namespace)) {
ValidationEvent privateAccessValidationEvent = getPrivateAccessValidationEvent(rel);
events.add(privateAccessValidationEvent);
events.add(getPrivateAccessValidationEvent(rel));
}
}
}

private ValidationEvent getPrivateAccessValidationEvent(Relationship relationship) {
ShapeId neighborId = relationship.expectNeighborShape().getId();
String message = String.format(
"This shape has an invalid %s relationship that targets a private shape, `%s`, in another namespace.",
relationship.getRelationshipType().toString().toLowerCase(Locale.US),
relationship.getNeighborShape().get().getId());
neighborId
);

// For now, emit a warning for trait relationships instead of an error. This is because private access on trait
// relationships was not being validated in the past, so emitting a warning maintains backward compatibility.
Expand Down