Skip to content

Commit

Permalink
Fix NPE when docId is null when ServiceTrait.equals is called
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFossAWS committed Aug 2, 2023
1 parent 6279f9d commit ea9544b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
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);
}
}

0 comments on commit ea9544b

Please sign in to comment.