Skip to content

Commit e7e0521

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

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ public boolean equals(Object other) {
232232
&& arnNamespace.equals(os.arnNamespace)
233233
&& cloudFormationName.equals(os.cloudFormationName)
234234
&& cloudTrailEventSource.equals(os.cloudTrailEventSource)
235-
&& docId == null
235+
&& (docId == null
236236
? os.docId == null
237-
: docId.equals(os.docId)
237+
: docId.equals(os.docId))
238238
&& endpointPrefix.equals(os.endpointPrefix);
239239
}
240240
}

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
import static org.hamcrest.MatcherAssert.assertThat;
1919
import static org.hamcrest.Matchers.equalTo;
2020
import static org.hamcrest.Matchers.instanceOf;
21-
import static org.junit.jupiter.api.Assertions.assertFalse;
22-
import static org.junit.jupiter.api.Assertions.assertThrows;
23-
import static org.junit.jupiter.api.Assertions.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.*;
2422

2523
import java.util.Optional;
2624
import org.junit.jupiter.api.Test;
@@ -126,4 +124,22 @@ public void loadsFromModel() {
126124
assertFalse(trait.getDocId().isPresent());
127125
assertThat(trait.resolveDocId(service), equalTo("some-value-2018-03-17"));
128126
}
127+
128+
@Test
129+
public void equality() {
130+
Node node1 = Node.parse("{\"sdkId\": \"Foo1\", \"arnNamespace\": \"service\", \"cloudFormationName\": \"Baz\", "
131+
+ "\"endpointPrefix\": \"endpoint-prefix\"}");
132+
133+
Node node2 = Node.parse("{\"sdkId\": \"Foo2\", \"arnNamespace\": \"service\", \"cloudFormationName\": \"Baz\", "
134+
+ "\"endpointPrefix\": \"endpoint-prefix\"}");
135+
136+
TraitFactory provider = TraitFactory.createServiceFactory();
137+
Optional<Trait> trait1 = provider.createTrait(ServiceTrait.ID, ShapeId.from("ns.foo#foo1"), node1);
138+
Optional<Trait> trait2 = provider.createTrait(ServiceTrait.ID, ShapeId.from("ns.foo#foo2"), node2);
139+
140+
ServiceTrait serviceTrait1 = (ServiceTrait) trait1.get();
141+
ServiceTrait serviceTrait2 = (ServiceTrait) trait2.get();
142+
143+
assertNotEquals(serviceTrait1, serviceTrait2);
144+
}
129145
}

0 commit comments

Comments
 (0)