Skip to content

Commit 0fce198

Browse files
Enable & fix inspection: Explicit argument can be lambda (#2821)
Reports method calls that accept a non-trivial expression and can be replaced with an equivalent method call which accepts a lambda instead. Converting an expression to a lambda ensures that the expression won't be evaluated if it's not used inside the method. For example, `optional .orElse(createDefaultValue())` can be converted to `optional.orElseGet (this::createDefaultValue)`.
1 parent ada07d1 commit 0fce198

File tree

10 files changed

+18
-16
lines changed

10 files changed

+18
-16
lines changed

.idea/inspectionProfiles/AWS_Java_SDK_2_0.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/profiles/src/main/java/software/amazon/awssdk/profiles/ProfileFileLocation.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ private ProfileFileLocation() {
4545
public static Path configurationFilePath() {
4646
return resolveProfileFilePath(
4747
ProfileFileSystemSetting.AWS_CONFIG_FILE.getStringValue()
48-
.orElse(Paths.get(userHomeDirectory(),
49-
".aws", "config").toString()));
48+
.orElseGet(() -> Paths.get(userHomeDirectory(),
49+
".aws", "config").toString()));
5050
}
5151

5252
/**
@@ -57,8 +57,8 @@ public static Path configurationFilePath() {
5757
public static Path credentialsFilePath() {
5858
return resolveProfileFilePath(
5959
ProfileFileSystemSetting.AWS_SHARED_CREDENTIALS_FILE.getStringValue()
60-
.orElse(Paths.get(userHomeDirectory(),
61-
".aws", "credentials").toString()));
60+
.orElseGet(() -> Paths.get(userHomeDirectory(),
61+
".aws", "credentials").toString()));
6262
}
6363

6464
/**

core/profiles/src/main/java/software/amazon/awssdk/profiles/internal/ProfileFileReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private static int findEarliestMatch(String line, String... searchPatterns) {
284284
.mapToInt(line::indexOf)
285285
.filter(location -> location >= 0)
286286
.min()
287-
.orElse(line.length());
287+
.orElseGet(line::length);
288288
}
289289

290290
private static boolean isEmptyLine(String line) {

core/protocols/aws-query-protocol/src/main/java/software/amazon/awssdk/protocols/query/internal/unmarshall/AwsXmlErrorUnmarshaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private String getMessage(XmlElement errorRoot) {
172172
*/
173173
private String getRequestId(SdkHttpFullResponse response, XmlElement document) {
174174
XmlElement requestId = document.getOptionalElementByName("RequestId")
175-
.orElse(document.getElementByName("RequestID"));
175+
.orElseGet(() -> document.getElementByName("RequestID"));
176176
return requestId != null ?
177177
requestId.textContent() :
178178
matchRequestIdHeaders(response);

core/protocols/aws-query-protocol/src/main/java/software/amazon/awssdk/protocols/query/internal/unmarshall/QueryProtocolUnmarshaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private QueryProtocolUnmarshaller(Builder builder) {
6969

7070
public <TypeT extends SdkPojo> Pair<TypeT, Map<String, String>> unmarshall(SdkPojo sdkPojo,
7171
SdkHttpFullResponse response) {
72-
XmlElement document = response.content().map(XmlDomParser::parse).orElse(XmlElement.empty());
72+
XmlElement document = response.content().map(XmlDomParser::parse).orElseGet(XmlElement::empty);
7373
XmlElement resultRoot = hasResultWrapper ? document.getFirstChild() : document;
7474
return Pair.of(unmarshall(sdkPojo, resultRoot, response), parseMetadata(document));
7575
}

http-client-spi/src/main/java/software/amazon/awssdk/http/SystemPropertyTlsKeyManagersProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static Optional<String> getKeyStore() {
7575

7676
private static String getKeyStoreType() {
7777
return SystemSettingUtils.resolveSetting(SSL_KEY_STORE_TYPE)
78-
.orElse(KeyStore.getDefaultType());
78+
.orElseGet(KeyStore::getDefaultType);
7979
}
8080

8181
private static Optional<String> getKeyStorePassword() {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ public static Builder builder() {
126126
private EventLoopGroup resolveEventLoopGroup(DefaultBuilder builder) {
127127
int numThreads = Optional.ofNullable(builder.numberOfThreads).orElse(0);
128128
ThreadFactory threadFactory = Optional.ofNullable(builder.threadFactory)
129-
.orElse(new ThreadFactoryBuilder().threadNamePrefix("aws-java-sdk-NettyEventLoop")
130-
.build());
129+
.orElseGet(() -> new ThreadFactoryBuilder()
130+
.threadNamePrefix("aws-java-sdk-NettyEventLoop")
131+
.build());
131132
return new NioEventLoopGroup(numThreads, threadFactory);
132133
/*
133134
Need to investigate why epoll is raising channel inactive after successful response that causes

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public Exception transformException(Exception crtRuntimeException) {
5353
Exception exception = crtS3RuntimeExceptionOptional
5454
.filter(CrtErrorHandler::isErrorDetailsAvailable)
5555
.map(e -> getServiceSideException(e))
56-
.orElse(SdkClientException.create(crtRuntimeException.getMessage(), crtRuntimeException));
56+
.orElseGet(() -> SdkClientException.create(crtRuntimeException.getMessage(), crtRuntimeException));
5757
return exception;
5858
}
5959

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ public <T> T option(TransferConfigurationOption<T> option) {
7777
public boolean resolveUploadDirectoryRecursive(UploadDirectoryRequest request) {
7878
return request.overrideConfiguration()
7979
.flatMap(UploadDirectoryOverrideConfiguration::recursive)
80-
.orElse(options.get(UPLOAD_DIRECTORY_RECURSIVE));
80+
.orElseGet(() -> options.get(UPLOAD_DIRECTORY_RECURSIVE));
8181
}
8282

8383
public boolean resolveUploadDirectoryFollowSymbolicLinks(UploadDirectoryRequest request) {
8484
return request.overrideConfiguration()
8585
.flatMap(UploadDirectoryOverrideConfiguration::followSymbolicLinks)
86-
.orElse(options.get(UPLOAD_DIRECTORY_FOLLOW_SYMBOLIC_LINKS));
86+
.orElseGet(() -> options.get(UPLOAD_DIRECTORY_FOLLOW_SYMBOLIC_LINKS));
8787
}
8888

8989
public int resolveUploadDirectoryMaxDepth(UploadDirectoryRequest request) {
9090
return request.overrideConfiguration()
9191
.flatMap(UploadDirectoryOverrideConfiguration::maxDepth)
92-
.orElse(options.get(UPLOAD_DIRECTORY_MAX_DEPTH));
92+
.orElseGet(() -> options.get(UPLOAD_DIRECTORY_MAX_DEPTH));
9393
}
9494

9595
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class ChecksumCalculatingAsyncRequestBody implements AsyncRequestBody {
3535
public ChecksumCalculatingAsyncRequestBody(SdkHttpRequest request, AsyncRequestBody wrapped, SdkChecksum sdkChecksum) {
3636
this.contentLength = request.firstMatchingHeader("Content-Length")
3737
.map(Long::parseLong)
38-
.orElse(wrapped.contentLength()
39-
.orElse(null));
38+
.orElseGet(() -> wrapped.contentLength()
39+
.orElse(null));
4040
this.wrapped = wrapped;
4141
this.sdkChecksum = sdkChecksum;
4242
}

0 commit comments

Comments
 (0)