This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 5c3bfd95c6 Cleanup, no functional change
5c3bfd95c6 is described below
commit 5c3bfd95c654f7c5cc045c5473047d38cc14e3e2
Author: remm <[email protected]>
AuthorDate: Wed Mar 12 23:58:38 2025 +0100
Cleanup, no functional change
---
.../apache/catalina/connector/CoyoteAdapter.java | 21 +++++++---------
.../apache/catalina/connector/CoyoteReader.java | 9 +------
.../apache/catalina/connector/CoyoteWriter.java | 8 +++----
.../org/apache/catalina/connector/InputBuffer.java | 11 ++-------
.../apache/catalina/connector/OutputBuffer.java | 20 +++++++---------
java/org/apache/catalina/connector/Request.java | 28 +++++++++-------------
.../apache/catalina/connector/RequestFacade.java | 2 +-
java/org/apache/catalina/connector/Response.java | 28 ++++++----------------
.../apache/catalina/connector/ResponseFacade.java | 2 +-
9 files changed, 44 insertions(+), 85 deletions(-)
diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java
b/java/org/apache/catalina/connector/CoyoteAdapter.java
index 14b8294979..07e844a367 100644
--- a/java/org/apache/catalina/connector/CoyoteAdapter.java
+++ b/java/org/apache/catalina/connector/CoyoteAdapter.java
@@ -811,7 +811,7 @@ public class CoyoteAdapter implements Adapter {
// Filter TRACE method
if (!connector.getAllowTrace() && req.method().equals("TRACE")) {
Wrapper wrapper = request.getWrapper();
- String header = null;
+ StringBuilder header = null;
if (wrapper != null) {
String[] methods = wrapper.getServletMethods();
if (methods != null) {
@@ -820,15 +820,15 @@ public class CoyoteAdapter implements Adapter {
continue;
}
if (header == null) {
- header = method;
+ header = new StringBuilder(method);
} else {
- header += ", " + method;
+ header.append(", ").append(method);
}
}
}
}
if (header != null) {
- res.addHeader("Allow", header);
+ res.addHeader("Allow", header.toString());
}
response.sendError(405, sm.getString("coyoteAdapter.trace"));
// Safe to skip the remainder of this method.
@@ -1121,15 +1121,13 @@ public class CoyoteAdapter implements Adapter {
return false;
}
- int pos = 0;
- int index = 0;
-
-
// The URL must start with '/' (or '\' that will be replaced soon)
if (b[start] != (byte) '/' && b[start] != (byte) '\\') {
return false;
}
+ int pos;
+
// Replace '\' with '/'
// Check for null byte
for (pos = start; pos < end; pos++) {
@@ -1167,7 +1165,7 @@ public class CoyoteAdapter implements Adapter {
uriBC.setEnd(end);
- index = 0;
+ int index = 0;
// Resolve occurrences of "/./" in the normalized path
while (true) {
@@ -1234,11 +1232,10 @@ public class CoyoteAdapter implements Adapter {
byte[] bytes = undecodedURI.getBytes();
int start = undecodedURI.getStart();
int end = undecodedURI.getEnd();
- int segmentStart = -1;
- int segmentEnd = -1;
// Find first segment
- segmentStart = undecodedURI.indexOf('/', 0);
+ int segmentStart = undecodedURI.indexOf('/', 0);
+ int segmentEnd = -1;
if (segmentStart > -1) {
segmentEnd = undecodedURI.indexOf('/', segmentStart + 1);
}
diff --git a/java/org/apache/catalina/connector/CoyoteReader.java
b/java/org/apache/catalina/connector/CoyoteReader.java
index da6bc3a875..a88a340414 100644
--- a/java/org/apache/catalina/connector/CoyoteReader.java
+++ b/java/org/apache/catalina/connector/CoyoteReader.java
@@ -115,12 +115,6 @@ public class CoyoteReader extends BufferedReader {
}
- @Override
- public boolean markSupported() {
- return true;
- }
-
-
@Override
public void mark(int readAheadLimit) throws IOException {
ib.mark(readAheadLimit);
@@ -140,8 +134,6 @@ public class CoyoteReader extends BufferedReader {
lineBuffer = new char[MAX_LINE_LENGTH];
}
- String result = null;
-
int pos = 0;
int end = -1;
int skip = -1;
@@ -192,6 +184,7 @@ public class CoyoteReader extends BufferedReader {
}
}
+ String result;
if (aggregator == null) {
result = new String(lineBuffer, 0, end);
} else {
diff --git a/java/org/apache/catalina/connector/CoyoteWriter.java
b/java/org/apache/catalina/connector/CoyoteWriter.java
index 6868156f0a..f4aea5fe62 100644
--- a/java/org/apache/catalina/connector/CoyoteWriter.java
+++ b/java/org/apache/catalina/connector/CoyoteWriter.java
@@ -137,7 +137,7 @@ public class CoyoteWriter extends PrintWriter {
@Override
- public void write(char buf[], int off, int len) {
+ public void write(char[] buf, int off, int len) {
if (error) {
return;
@@ -153,7 +153,7 @@ public class CoyoteWriter extends PrintWriter {
@Override
- public void write(char buf[]) {
+ public void write(char[] buf) {
write(buf, 0, buf.length);
}
@@ -224,7 +224,7 @@ public class CoyoteWriter extends PrintWriter {
@Override
- public void print(char s[]) {
+ public void print(char[] s) {
write(s);
}
@@ -293,7 +293,7 @@ public class CoyoteWriter extends PrintWriter {
@Override
- public void println(char c[]) {
+ public void println(char[] c) {
print(c);
println();
}
diff --git a/java/org/apache/catalina/connector/InputBuffer.java
b/java/org/apache/catalina/connector/InputBuffer.java
index 6d5db65ec1..d93752d246 100644
--- a/java/org/apache/catalina/connector/InputBuffer.java
+++ b/java/org/apache/catalina/connector/InputBuffer.java
@@ -589,20 +589,14 @@ public class InputBuffer extends Reader implements
ByteChunk.ByteInputChannel, A
private boolean checkByteBufferEof() throws IOException {
if (bb.remaining() == 0) {
- int n = realReadBytes();
- if (n < 0) {
- return true;
- }
+ return realReadBytes() < 0;
}
return false;
}
private boolean checkCharBufferEof() throws IOException {
if (cb.remaining() == 0) {
- int n = realReadChars();
- if (n < 0) {
- return true;
- }
+ return realReadChars() < 0;
}
return false;
}
@@ -637,6 +631,5 @@ public class InputBuffer extends Reader implements
ByteChunk.ByteInputChannel, A
tmp.flip();
tmp.position(oldPosition);
cb = tmp;
- tmp = null;
}
}
diff --git a/java/org/apache/catalina/connector/OutputBuffer.java
b/java/org/apache/catalina/connector/OutputBuffer.java
index a1adae91aa..4d7e617e94 100644
--- a/java/org/apache/catalina/connector/OutputBuffer.java
+++ b/java/org/apache/catalina/connector/OutputBuffer.java
@@ -231,11 +231,7 @@ public class OutputBuffer extends Writer {
coyoteResponse.setContentLength(bb.remaining());
}
- if (coyoteResponse.getStatus() ==
HttpServletResponse.SC_SWITCHING_PROTOCOLS) {
- doFlush(true);
- } else {
- doFlush(false);
- }
+ doFlush(coyoteResponse.getStatus() ==
HttpServletResponse.SC_SWITCHING_PROTOCOLS);
closed = true;
// The request should have been completely read by the time the
response
@@ -338,7 +334,7 @@ public class OutputBuffer extends Writer {
}
- public void write(byte b[], int off, int len) throws IOException {
+ public void write(byte[] b, int off, int len) throws IOException {
if (suspended) {
return;
@@ -360,7 +356,7 @@ public class OutputBuffer extends Writer {
}
- private void writeBytes(byte b[], int off, int len) throws IOException {
+ private void writeBytes(byte[] b, int off, int len) throws IOException {
if (closed) {
throw new IOException(sm.getString("outputBuffer.closed"));
@@ -486,7 +482,7 @@ public class OutputBuffer extends Writer {
@Override
- public void write(char c[]) throws IOException {
+ public void write(char[] c) throws IOException {
if (suspended) {
return;
@@ -498,7 +494,7 @@ public class OutputBuffer extends Writer {
@Override
- public void write(char c[], int off, int len) throws IOException {
+ public void write(char[] c, int off, int len) throws IOException {
if (suspended) {
return;
@@ -656,7 +652,7 @@ public class OutputBuffer extends Writer {
*
* @throws IOException Writing overflow data to the output channel failed
*/
- public void append(byte src[], int off, int len) throws IOException {
+ public void append(byte[] src, int off, int len) throws IOException {
if (bb.remaining() == 0) {
appendByteArray(src, off, len);
} else {
@@ -679,7 +675,7 @@ public class OutputBuffer extends Writer {
*
* @throws IOException Writing overflow data to the output channel failed
*/
- public void append(char src[], int off, int len) throws IOException {
+ public void append(char[] src, int off, int len) throws IOException {
// if we have limit and we're below
if (len <= cb.capacity() - cb.limit()) {
transfer(src, off, len, cb);
@@ -730,7 +726,7 @@ public class OutputBuffer extends Writer {
}
- private void appendByteArray(byte src[], int off, int len) throws
IOException {
+ private void appendByteArray(byte[] src, int off, int len) throws
IOException {
if (len == 0) {
return;
}
diff --git a/java/org/apache/catalina/connector/Request.java
b/java/org/apache/catalina/connector/Request.java
index a6b0beb7ed..ee7817d962 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -580,7 +580,7 @@ public class Request implements HttpServletRequest {
* this request
*/
public boolean getDiscardFacades() {
- return (connector == null) ? true : connector.getDiscardFacades();
+ return connector == null || connector.getDiscardFacades();
}
@@ -1258,7 +1258,7 @@ public class Request implements HttpServletRequest {
// Add the path info, if there is any
String pathInfo = getPathInfo();
- String requestPath = null;
+ String requestPath;
if (pathInfo == null) {
requestPath = servletPath;
@@ -1267,7 +1267,7 @@ public class Request implements HttpServletRequest {
}
int pos = requestPath.lastIndexOf('/');
- String relative = null;
+ String relative;
if (context.getDispatchersUseEncodedPaths()) {
if (pos >= 0) {
relative = URLEncoder.DEFAULT.encode(requestPath.substring(0,
pos + 1), StandardCharsets.UTF_8) + path;
@@ -1375,12 +1375,12 @@ public class Request implements HttpServletRequest {
if (context == null) {
return;
}
- Object listeners[] = context.getApplicationEventListeners();
+ Object[] listeners = context.getApplicationEventListeners();
if (listeners == null || listeners.length == 0) {
return;
}
boolean replaced = (oldValue != null);
- ServletRequestAttributeEvent event = null;
+ ServletRequestAttributeEvent event;
if (replaced) {
event = new
ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name,
oldValue);
} else {
@@ -1416,7 +1416,7 @@ public class Request implements HttpServletRequest {
*/
private void notifyAttributeRemoved(String name, Object value) {
Context context = getContext();
- Object listeners[] = context.getApplicationEventListeners();
+ Object[] listeners = context.getApplicationEventListeners();
if (listeners == null || listeners.length == 0) {
return;
}
@@ -1927,7 +1927,7 @@ public class Request implements HttpServletRequest {
return input;
}
StringBuilder result = new StringBuilder(input.length());
- result.append(input.substring(0, nextSemiColon));
+ result.append(input, 0, nextSemiColon);
while (true) {
int nextSlash = input.indexOf('/', nextSemiColon);
if (nextSlash == -1) {
@@ -1938,7 +1938,7 @@ public class Request implements HttpServletRequest {
result.append(input.substring(nextSlash));
break;
} else {
- result.append(input.substring(nextSlash, nextSemiColon));
+ result.append(input, nextSlash, nextSemiColon);
}
}
@@ -2325,7 +2325,7 @@ public class Request implements HttpServletRequest {
return;
}
- if (response != null) {
+ if (response != null && context != null) {
Cookie newCookie =
ApplicationSessionCookieConfig.createSessionCookie(context, newSessionId,
isSecure());
response.addSessionCookieInternal(newCookie);
}
@@ -2519,7 +2519,7 @@ public class Request implements HttpServletRequest {
// Equals sign
postSize++;
// Value length
- postSize += part.getSize();
+ postSize += (int) part.getSize();
// Value separator
postSize++;
if (postSize > maxPostSize) {
@@ -2537,18 +2537,14 @@ public class Request implements HttpServletRequest {
}
} catch (InvalidContentTypeException e) {
partsParseException = new ServletException(e);
- return;
} catch (SizeException e) {
checkSwallowInput();
partsParseException = new InvalidParameterException(e,
HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
- return;
} catch (IOException e) {
partsParseException = e;
- return;
} catch (IllegalStateException e) {
checkSwallowInput();
partsParseException = e;
- return;
}
}
@@ -2845,7 +2841,7 @@ public class Request implements HttpServletRequest {
new InvalidParameterException(message,
HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
return;
}
- byte[] formData = null;
+ byte[] formData;
if (len < CACHED_POST_LEN) {
if (postData == null) {
postData = new byte[CACHED_POST_LEN];
@@ -2879,7 +2875,6 @@ public class Request implements HttpServletRequest {
formData = readChunkedPostBody();
} catch (IllegalStateException ise) {
parametersParseException = ise;
- return;
} catch (IOException e) {
Context context = getContext();
if (context != null && context.getLogger().isDebugEnabled()) {
@@ -2894,7 +2889,6 @@ public class Request implements HttpServletRequest {
} else {
parametersParseException = new
InvalidParameterException(new BadRequestException(e));
}
- return;
}
if (formData != null) {
parameters.processParameters(formData, 0, formData.length);
diff --git a/java/org/apache/catalina/connector/RequestFacade.java
b/java/org/apache/catalina/connector/RequestFacade.java
index 1a2f335076..54be51b02d 100644
--- a/java/org/apache/catalina/connector/RequestFacade.java
+++ b/java/org/apache/catalina/connector/RequestFacade.java
@@ -58,7 +58,7 @@ public class RequestFacade implements HttpServletRequest {
/**
* The wrapped request.
*/
- protected Request request = null;
+ protected Request request;
/**
diff --git a/java/org/apache/catalina/connector/Response.java
b/java/org/apache/catalina/connector/Response.java
index 0baee3e1e7..23369f0f7c 100644
--- a/java/org/apache/catalina/connector/Response.java
+++ b/java/org/apache/catalina/connector/Response.java
@@ -673,11 +673,7 @@ public class Response implements HttpServletResponse {
log.warn(sm.getString("coyoteResponse.encoding.invalid",
encoding), e);
return;
}
- if (encoding == null) {
- isCharacterEncodingSet = false;
- } else {
- isCharacterEncodingSet = true;
- }
+ isCharacterEncodingSet = encoding != null;
}
@@ -700,11 +696,7 @@ public class Response implements HttpServletResponse {
}
getCoyoteResponse().setCharsetHolder(CharsetHolder.getInstance(charset));
- if (charset == null) {
- isCharacterEncodingSet = false;
- } else {
- isCharacterEncodingSet = true;
- }
+ isCharacterEncodingSet = charset != null;
}
@@ -1285,7 +1277,7 @@ public class Response implements HttpServletResponse {
private static boolean doIsEncodeable(Context context, Request hreq,
Session session, String location) {
// Is this a valid absolute URL?
- URL url = null;
+ URL url;
try {
URI uri = new URI(location);
url = uri.toURL();
@@ -1327,9 +1319,7 @@ public class Response implements HttpServletResponse {
return false;
}
String tok = ";" + SessionConfig.getSessionUriParamName(context) +
"=" + session.getIdInternal();
- if (file.indexOf(tok, contextPath.length()) >= 0) {
- return false;
- }
+ return file.indexOf(tok, contextPath.length()) < 0;
}
// This URL belongs to our web application, so it is encodeable
@@ -1352,7 +1342,7 @@ public class Response implements HttpServletResponse {
protected String toAbsolute(String location) {
if (location == null) {
- return location;
+ return null;
}
boolean leadingSlash = location.startsWith("/");
@@ -1442,7 +1432,6 @@ public class Response implements HttpServletResponse {
char[] c = cc.getChars();
int start = cc.getStart();
int end = cc.getEnd();
- int index = 0;
int startIndex = 0;
// Advance past the first three / characters (should place index just
@@ -1453,7 +1442,7 @@ public class Response implements HttpServletResponse {
}
// Remove /./
- index = startIndex;
+ int index = startIndex;
while (true) {
index = cc.indexOf("/./", 0, 3, index);
if (index < 0) {
@@ -1516,10 +1505,7 @@ public class Response implements HttpServletResponse {
return false;
}
pos = uri.indexOf('/', pos + 3);
- if (pos < 0) {
- return false;
- }
- return true;
+ return pos >= 0;
}
/**
diff --git a/java/org/apache/catalina/connector/ResponseFacade.java
b/java/org/apache/catalina/connector/ResponseFacade.java
index f585fee7f4..0699f5de2d 100644
--- a/java/org/apache/catalina/connector/ResponseFacade.java
+++ b/java/org/apache/catalina/connector/ResponseFacade.java
@@ -60,7 +60,7 @@ public class ResponseFacade implements HttpServletResponse {
/**
* The wrapped response.
*/
- protected Response response = null;
+ protected Response response;
// --------------------------------------------------------- Public Methods
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]