Skip to content

Commit f7705c4

Browse files
Enable & fix inspection: equals() called on enum value (#2819)
Reports `equals()` calls on enum constants. Such calls can be replaced by an identity comparison (`==`) because two enum constants are equal only when they have the same identity. A quick-fix is available to change the call to a comparison. Example: ``` boolean foo(MyEnum value) { return value.equals(MyEnum.FOO); } ``` After the quick-fix is applied: ``` boolean foo(MyEnum value) { return value == MyEnum.FOO; } ```
1 parent 91d495a commit f7705c4

File tree

14 files changed

+18
-17
lines changed

14 files changed

+18
-17
lines changed

.idea/inspectionProfiles/AWS_Java_SDK_2_0.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codegen/src/main/java/software/amazon/awssdk/codegen/AddOperations.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ final class AddOperations {
5454
}
5555

5656
private static boolean isAuthenticated(Operation op) {
57-
return op.getAuthtype() == null || !op.getAuthtype().equals(AuthType.NONE);
57+
return op.getAuthtype() == null || op.getAuthtype() != AuthType.NONE;
5858
}
5959

6060
private static String getOperationDocumentation(final Output output, final Shape outputShape) {

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/JsonProtocolSpec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,6 @@ private String protocolFactoryLiteral(IntermediateModel model, OperationModel op
450450
}
451451

452452
private boolean isRestJson(IntermediateModel model) {
453-
return Protocol.REST_JSON.equals(model.getMetadata().getProtocol());
453+
return model.getMetadata().getProtocol() == Protocol.REST_JSON;
454454
}
455455
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/ProtocolSpec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ default CodeBlock streamingMarshallerCode(IntermediateModel model, OperationMode
128128
builder.add(".requiresLength(true)");
129129
}
130130

131-
if (AuthType.V4_UNSIGNED_BODY.equals(opModel.getAuthType())) {
131+
if (opModel.getAuthType() == AuthType.V4_UNSIGNED_BODY) {
132132
builder.add(".transferEncoding(true)");
133133
}
134134

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/ApplyUserAgentStage.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ private String addUserAgentSuffix(StringBuilder userAgent, SdkClientConfiguratio
138138
}
139139

140140
private String clientName(ClientType clientType) {
141-
if (clientType.equals(ClientType.SYNC)) {
141+
if (clientType == ClientType.SYNC) {
142142
return clientConfig.option(SdkClientOption.SYNC_HTTP_CLIENT).clientName();
143143
}
144144

145-
if (clientType.equals(ClientType.ASYNC)) {
145+
if (clientType == ClientType.ASYNC) {
146146
return clientConfig.option(SdkClientOption.ASYNC_HTTP_CLIENT).clientName();
147147
}
148148

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/NettyRequestExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private boolean tryConfigurePipeline() {
208208
}
209209

210210
pipeline.addLast(LastHttpContentHandler.create());
211-
if (Protocol.HTTP2.equals(protocol)) {
211+
if (protocol == Protocol.HTTP2) {
212212
pipeline.addLast(FlushOnReadHandler.getInstance());
213213
}
214214
pipeline.addLast(new HttpStreamsClientHandler());

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/ResponseHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public void onSubscribe(Subscription subscription) {
227227

228228
private Subscription resolveSubscription(Subscription subscription) {
229229
// For HTTP2 we send a RST_STREAM frame on cancel to stop the service from sending more data
230-
if (Protocol.HTTP2.equals(ChannelAttributeKey.getProtocolNow(channelContext.channel()))) {
230+
if (ChannelAttributeKey.getProtocolNow(channelContext.channel()) == Protocol.HTTP2) {
231231
return new Http2ResetSendingSubscription(channelContext, subscription);
232232
} else {
233233
return subscription;

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/SslContextProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public SslContext sslContext() {
7070
* /SslUtils.java
7171
*/
7272
private List<String> getCiphers() {
73-
return protocol.equals(Protocol.HTTP2) ? Http2SecurityUtil.CIPHERS : null;
73+
return protocol == Protocol.HTTP2 ? Http2SecurityUtil.CIPHERS : null;
7474
}
7575

7676
private TrustManagerFactory getTrustManager(NettyConfiguration configuration) {

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/extensions/VersionedRecordExtension.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private static class VersionAttribute implements StaticAttributeTag {
7777
@Override
7878
public Consumer<StaticTableMetadata.Builder> modifyMetadata(String attributeName,
7979
AttributeValueType attributeValueType) {
80-
if (!AttributeValueType.N.equals(attributeValueType)) {
80+
if (attributeValueType != AttributeValueType.N) {
8181
throw new IllegalArgumentException(String.format(
8282
"Attribute '%s' of type %s is not a suitable type to be used as a version attribute. Only type 'N' " +
8383
"is supported.", attributeName, attributeValueType.name()));

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticTableMetadata.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public Builder addIndexSortKey(String indexName, String attributeName, Attribute
301301
public Builder markAttributeAsKey(String attributeName, AttributeValueType attributeValueType) {
302302
KeyAttributeMetadata existing = keyAttributes.get(attributeName);
303303

304-
if (existing != null && !existing.attributeValueType().equals(attributeValueType)) {
304+
if (existing != null && existing.attributeValueType() != attributeValueType) {
305305
throw new IllegalArgumentException("Attempt to mark an attribute as a key with a different "
306306
+ "AttributeValueType than one that has already been recorded.");
307307
}

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/S3CrtDataPublisher.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ public void deliverData(ByteBuffer byteBuffer) {
9191

9292
private void notifyErrorIfNeeded(Subscriber<? super ByteBuffer> subscriber) {
9393
Event event = buffer.peek();
94-
if (event != null && event.type().equals(EventType.ERROR)) {
94+
if (event != null && event.type() == EventType.ERROR) {
9595
isDone = true;
9696
subscriber.onError(((ErrorEvent) event).error());
9797
}
9898
}
9999

100100
private boolean isTerminalEvent(Event event) {
101-
return event.type().equals(EventType.ERROR) ||
102-
event.type().equals(EventType.COMPLETE) ||
103-
event.type().equals(EventType.CANCEL);
101+
return event.type() == EventType.ERROR ||
102+
event.type() == EventType.COMPLETE ||
103+
event.type() == EventType.CANCEL;
104104
}
105105

106106
private void handleTerminalEvent(Event event) {

services/s3/src/main/java/software/amazon/awssdk/services/s3/checksums/ChecksumsEnabledValidator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static boolean shouldRecordChecksum(SdkRequest sdkRequest,
9898

9999
ClientType actualClientType = executionAttributes.getAttribute(SdkExecutionAttribute.CLIENT_TYPE);
100100

101-
if (!expectedClientType.equals(actualClientType)) {
101+
if (expectedClientType != actualClientType) {
102102
return false;
103103
}
104104

services/s3control/src/main/java/software/amazon/awssdk/services/s3control/internal/interceptors/PayloadSigningInterceptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class PayloadSigningInterceptor implements ExecutionInterceptor {
3434
public Optional<RequestBody> modifyHttpContent(Context.ModifyHttpRequest context,
3535
ExecutionAttributes executionAttributes) {
3636
executionAttributes.putAttribute(S3SignerExecutionAttribute.ENABLE_PAYLOAD_SIGNING, true);
37-
if (!context.requestBody().isPresent() && context.httpRequest().method().equals(SdkHttpMethod.POST)) {
37+
if (!context.requestBody().isPresent() && context.httpRequest().method() == SdkHttpMethod.POST) {
3838
return Optional.of(RequestBody.fromBytes(new byte[0]));
3939
}
4040

test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/BenchmarkResultProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private boolean validateBenchmarkParams(SdkBenchmarkParams current, SdkBenchmark
166166
return true;
167167
}
168168

169-
return Objects.equals(current.getMode(), baseline.getMode());
169+
return current.getMode() == baseline.getMode();
170170
}
171171

172172
private String serializeResult(List<SdkBenchmarkResult> currentData) {

0 commit comments

Comments
 (0)