Skip to content

Commit ea9544b

Browse files
committed
Fix NPE when docId is null when ServiceTrait.equals is called
1 parent 6279f9d commit ea9544b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/ServiceTrait.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ public boolean equals(Object other) {
232232
&& arnNamespace.equals(os.arnNamespace)
233233
&& cloudFormationName.equals(os.cloudFormationName)
234234
&& cloudTrailEventSource.equals(os.cloudTrailEventSource)
235-
&& docId == null
236-
? os.docId == null
237-
: docId.equals(os.docId)
235+
&& Objects.equals(docId, os.docId)
238236
&& endpointPrefix.equals(os.endpointPrefix);
239237
}
240238
}

smithy-aws-traits/src/test/java/software/amazon/smithy/aws/traits/ServiceTraitTest.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import static org.hamcrest.Matchers.equalTo;
2020
import static org.hamcrest.Matchers.instanceOf;
2121
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2223
import static org.junit.jupiter.api.Assertions.assertThrows;
2324
import static org.junit.jupiter.api.Assertions.assertTrue;
24-
2525
import java.util.Optional;
2626
import org.junit.jupiter.api.Test;
2727
import software.amazon.smithy.model.Model;
@@ -126,4 +126,22 @@ public void loadsFromModel() {
126126
assertFalse(trait.getDocId().isPresent());
127127
assertThat(trait.resolveDocId(service), equalTo("some-value-2018-03-17"));
128128
}
129+
130+
@Test
131+
public void equality() {
132+
Node node1 = Node.parse("{\"sdkId\": \"Foo1\", \"arnNamespace\": \"service\", \"cloudFormationName\": \"Baz\", "
133+
+ "\"endpointPrefix\": \"endpoint-prefix\"}");
134+
135+
Node node2 = Node.parse("{\"sdkId\": \"Foo2\", \"arnNamespace\": \"service\", \"cloudFormationName\": \"Baz\", "
136+
+ "\"endpointPrefix\": \"endpoint-prefix\"}");
137+
138+
TraitFactory provider = TraitFactory.createServiceFactory();
139+
Optional<Trait> trait1 = provider.createTrait(ServiceTrait.ID, ShapeId.from("ns.foo#foo1"), node1);
140+
Optional<Trait> trait2 = provider.createTrait(ServiceTrait.ID, ShapeId.from("ns.foo#foo2"), node2);
141+
142+
ServiceTrait serviceTrait1 = (ServiceTrait) trait1.get();
143+
ServiceTrait serviceTrait2 = (ServiceTrait) trait2.get();
144+
145+
assertNotEquals(serviceTrait1, serviceTrait2);
146+
}
129147
}

0 commit comments

Comments
 (0)