Improve usage of String.substring()

Closes gh-23923
This commit is contained in:
stsypanov 2019-11-03 22:05:12 +02:00 committed by Sam Brannen
parent f9c1f136c3
commit 9da15ee23a
5 changed files with 11 additions and 13 deletions

View File

@ -127,9 +127,9 @@ public class AspectMetadata implements Serializable {
*/
private String findPerClause(Class<?> aspectClass) {
String str = aspectClass.getAnnotation(Aspect.class).value();
str = str.substring(str.indexOf('(') + 1);
str = str.substring(0, str.length() - 1);
return str;
int beginIndex = str.indexOf('(') + 1;
int endIndex = str.length() - 1;
return str.substring(beginIndex, endIndex);
}

View File

@ -221,7 +221,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
@Override
protected int extractUnquotedLink(int position, String content, Set<ContentChunkInfo> result) {
if (content.substring(position, position + 4).equals("url(")) {
if (content.startsWith("url(", position)) {
// Ignore, UrlFunctionContentParser will take care
}
else if (logger.isTraceEnabled()) {

View File

@ -182,7 +182,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
@Override
protected int extractLink(int index, String content, SortedSet<ContentChunkInfo> linksToAdd) {
if (content.substring(index, index + 4).equals("url(")) {
if (content.startsWith("url(", index)) {
// Ignore, UrlLinkParser will take care
}
else if (logger.isTraceEnabled()) {

View File

@ -147,11 +147,10 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
"At least 2 characters ([]) required in attributes CSV string '" + propString + "'");
}
String name = tok.substring(0, eqIdx);
String value = tok.substring(eqIdx + 1);
// Delete first and last characters of value: { and }
value = value.substring(1);
value = value.substring(0, value.length() - 1);
int beginIndex = eqIdx + 2;
int endIndex = tok.length() - 1;
String value = tok.substring(beginIndex, endIndex);
addStaticAttribute(name, value);
}

View File

@ -472,8 +472,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
private boolean validatePath(ServerHttpRequest request) {
String path = request.getURI().getPath();
int index = path.lastIndexOf('/') + 1;
String filename = path.substring(index);
return (filename.indexOf(';') == -1);
return path.indexOf(';', index) == -1;
}
protected boolean checkOrigin(ServerHttpRequest request, ServerHttpResponse response, HttpMethod... httpMethods)
@ -571,7 +570,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
sendMethodNotAllowed(response, HttpMethod.GET, HttpMethod.OPTIONS);
}
}
};
}
private class IframeHandler implements SockJsRequestHandler {
@ -622,6 +621,6 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
response.getHeaders().setETag(etagValue);
response.getBody().write(contentBytes);
}
};
}
}