This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 33c8ef24c6 Cleanup, no functional change
33c8ef24c6 is described below
commit 33c8ef24c6c0577a84a448b0d7366811f165629e
Author: remm <[email protected]>
AuthorDate: Wed Mar 12 23:58:38 2025 +0100
Cleanup, no functional change
---
.../apache/catalina/connector/CoyoteAdapter.java | 16 +++++++---------
.../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 | 18 +++++++++---------
.../apache/catalina/connector/RequestFacade.java | 2 +-
java/org/apache/catalina/connector/Response.java | 22 ++++++----------------
.../apache/catalina/connector/ResponseFacade.java | 2 +-
9 files changed, 39 insertions(+), 69 deletions(-)
diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java
b/java/org/apache/catalina/connector/CoyoteAdapter.java
index 3c09f245d2..c7711de617 100644
--- a/java/org/apache/catalina/connector/CoyoteAdapter.java
+++ b/java/org/apache/catalina/connector/CoyoteAdapter.java
@@ -815,7 +815,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) {
@@ -824,15 +824,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.
@@ -1123,15 +1123,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++) {
@@ -1168,7 +1166,7 @@ public class CoyoteAdapter implements Adapter {
uriBC.setEnd(end);
- index = 0;
+ int index = 0;
// Resolve occurrences of "/./" in the normalized path
while (true) {
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 daa84f4a97..b3ab8a8503 100644
--- a/java/org/apache/catalina/connector/InputBuffer.java
+++ b/java/org/apache/catalina/connector/InputBuffer.java
@@ -612,20 +612,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;
}
@@ -660,7 +654,6 @@ 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 dc6fb3cc53..5811ab1e35 100644
--- a/java/org/apache/catalina/connector/OutputBuffer.java
+++ b/java/org/apache/catalina/connector/OutputBuffer.java
@@ -243,11 +243,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
@@ -350,7 +346,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;
@@ -372,7 +368,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) {
return;
@@ -478,7 +474,7 @@ public class OutputBuffer extends Writer {
@Override
- public void write(char c[]) throws IOException {
+ public void write(char[] c) throws IOException {
if (suspended) {
return;
@@ -490,7 +486,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;
@@ -667,7 +663,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 {
@@ -690,7 +686,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);
@@ -741,7 +737,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 1744089d97..cf3795c47a 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -596,7 +596,7 @@ public class Request implements HttpServletRequest {
* this request
*/
public boolean getDiscardFacades() {
- return (connector == null) ? true : connector.getDiscardFacades();
+ return connector == null || connector.getDiscardFacades();
}
@@ -1331,7 +1331,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;
@@ -1340,7 +1340,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;
@@ -1466,12 +1466,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 {
@@ -1507,7 +1507,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;
}
@@ -2031,7 +2031,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) {
@@ -2042,7 +2042,7 @@ public class Request implements HttpServletRequest {
result.append(input.substring(nextSlash));
break;
} else {
- result.append(input.substring(nextSlash, nextSemiColon));
+ result.append(input, nextSlash, nextSemiColon);
}
}
@@ -2436,7 +2436,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);
}
diff --git a/java/org/apache/catalina/connector/RequestFacade.java
b/java/org/apache/catalina/connector/RequestFacade.java
index 84854e4857..0458f0b9e8 100644
--- a/java/org/apache/catalina/connector/RequestFacade.java
+++ b/java/org/apache/catalina/connector/RequestFacade.java
@@ -208,7 +208,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 40c2601595..f156a5d93a 100644
--- a/java/org/apache/catalina/connector/Response.java
+++ b/java/org/apache/catalina/connector/Response.java
@@ -736,11 +736,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;
}
@@ -1407,7 +1403,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();
@@ -1449,9 +1445,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
@@ -1474,7 +1468,7 @@ public class Response implements HttpServletResponse {
protected String toAbsolute(String location) {
if (location == null) {
- return location;
+ return null;
}
boolean leadingSlash = location.startsWith("/");
@@ -1574,7 +1568,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
@@ -1585,7 +1578,7 @@ public class Response implements HttpServletResponse {
}
// Remove /./
- index = startIndex;
+ int index = startIndex;
while (true) {
index = cc.indexOf("/./", 0, 3, index);
if (index < 0) {
@@ -1648,10 +1641,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 4d01367bbd..6926c6ee3d 100644
--- a/java/org/apache/catalina/connector/ResponseFacade.java
+++ b/java/org/apache/catalina/connector/ResponseFacade.java
@@ -123,7 +123,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]