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 when docId is null when ServiceTrait.equals is called #1903

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
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 @@ -232,9 +232,7 @@ public boolean equals(Object other) {
&& arnNamespace.equals(os.arnNamespace)
&& cloudFormationName.equals(os.cloudFormationName)
&& cloudTrailEventSource.equals(os.cloudTrailEventSource)
&& docId == null
? os.docId == null
: docId.equals(os.docId)
&& Objects.equals(docId, os.docId)
&& endpointPrefix.equals(os.endpointPrefix);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Optional;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.model.Model;
Expand Down Expand Up @@ -126,4 +126,22 @@ public void loadsFromModel() {
assertFalse(trait.getDocId().isPresent());
assertThat(trait.resolveDocId(service), equalTo("some-value-2018-03-17"));
}

@Test
public void equality() {
Node node1 = Node.parse("{\"sdkId\": \"Foo1\", \"arnNamespace\": \"service\", \"cloudFormationName\": \"Baz\", "
+ "\"endpointPrefix\": \"endpoint-prefix\"}");

Node node2 = Node.parse("{\"sdkId\": \"Foo2\", \"arnNamespace\": \"service\", \"cloudFormationName\": \"Baz\", "
+ "\"endpointPrefix\": \"endpoint-prefix\"}");

TraitFactory provider = TraitFactory.createServiceFactory();
Optional<Trait> trait1 = provider.createTrait(ServiceTrait.ID, ShapeId.from("ns.foo#foo1"), node1);
Optional<Trait> trait2 = provider.createTrait(ServiceTrait.ID, ShapeId.from("ns.foo#foo2"), node2);

ServiceTrait serviceTrait1 = (ServiceTrait) trait1.get();
ServiceTrait serviceTrait2 = (ServiceTrait) trait2.get();

assertNotEquals(serviceTrait1, serviceTrait2);
}
}