Skip to content

Enable & fix inspection: Single character string argument in String.indexOf() call #2823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/AWS_Java_SDK_2_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private Predicate<String> isUnused(String content) {
}

private boolean isNotReferenced(String contentWithoutImports, String importToCheck) {
String symbol = importToCheck.substring(importToCheck.lastIndexOf(".") + 1);
String symbol = importToCheck.substring(importToCheck.lastIndexOf('.') + 1);
return !Pattern.compile(String.format("\\b%s\\b", symbol)).matcher(contentWithoutImports).find();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private Predicate<String> isUnused(String content) {
}

private boolean isNotReferenced(String contentWithoutImports, String importToCheck) {
String symbol = importToCheck.substring(importToCheck.lastIndexOf(".") + 1);
String symbol = importToCheck.substring(importToCheck.lastIndexOf('.') + 1);
return !Pattern.compile(String.format("\\b%s\\b", symbol)).matcher(contentWithoutImports).find();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static String stripHtmlTags(String documentation) {
}

if (documentation.startsWith("<")) {
int startTagIndex = documentation.indexOf(">");
int closingTagIndex = documentation.lastIndexOf("<");
int startTagIndex = documentation.indexOf('>');
int closingTagIndex = documentation.lastIndexOf('<');
if (closingTagIndex > startTagIndex) {
documentation = stripHtmlTags(documentation.substring(startTagIndex + 1, closingTagIndex));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public String getTemplateImplType() {
}

public String getSimpleType() {
int startIndex = memberType.lastIndexOf(".");
int startIndex = memberType.lastIndexOf('.');
return memberType.substring(startIndex + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setVariableType(String variableType) {

public String getSimpleType() {
if (variableType.contains(".")) {
return variableType.substring(variableType.lastIndexOf(".") + 1);
return variableType.substring(variableType.lastIndexOf('.') + 1);
}
return variableType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public static TypeVariableName createBoundedTypeVariableName(String parameterNam
}

public static ClassName classNameFromFqcn(String fqcn) {
String basePath = fqcn.substring(0, fqcn.lastIndexOf("."));
String className = fqcn.substring(fqcn.lastIndexOf(".") + 1);
String basePath = fqcn.substring(0, fqcn.lastIndexOf('.'));
String className = fqcn.substring(fqcn.lastIndexOf('.') + 1);
return ClassName.get(basePath, className);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private String protocolEnumName(software.amazon.awssdk.codegen.model.intermediat

private ClassName baseExceptionClassName(IntermediateModel model) {
String exceptionPath = model.getSdkModeledExceptionBaseFqcn()
.substring(0, model.getSdkModeledExceptionBaseFqcn().lastIndexOf("."));
.substring(0, model.getSdkModeledExceptionBaseFqcn().lastIndexOf('.'));

return ClassName.get(exceptionPath, model.getSdkModeledExceptionBaseClassName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private String parseErrorCodeFromContents(JsonNode jsonContents) {
return null;
}
String code = errorCodeField.text();
int separator = code.lastIndexOf("#");
int separator = code.lastIndexOf('#');
return code.substring(separator + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ static String addStaticQueryParametersToRequest(SdkHttpFullRequest.Builder reque

String resourcePath = uriResourcePath;

int index = resourcePath.indexOf("?");
int index = resourcePath.indexOf('?');
if (index != -1) {
String queryString = resourcePath.substring(index + 1);
resourcePath = resourcePath.substring(0, index);

for (String s : queryString.split("[;&]")) {
index = s.indexOf("=");
index = s.indexOf('=');
if (index != -1) {
request.putRawQueryParameter(s.substring(0, index), s.substring(index + 1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private long parseContentLengthFromRange(String range) {
String end = range.substring(range.indexOf('-') + 1);

if (end.contains("/")) {
end = end.substring(0, end.indexOf("/"));
end = end.substring(0, end.indexOf('/'));
}

return Long.parseLong(end) - Long.parseLong(start) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private String removePrefix(String s) {
return null;
}

int lastIndex = s.lastIndexOf("/");
int lastIndex = s.lastIndexOf('/');
if (lastIndex > 0) {
return s.substring(lastIndex + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ private String getActualPath(LoggedRequest actual) {
}

private String removeTrailingSlash(String str) {
return (str.endsWith("/")) ? str.substring(0, str.lastIndexOf("/")) : str;
return (str.endsWith("/")) ? str.substring(0, str.lastIndexOf('/')) : str;
}
}