You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/05/18 10:35:50 UTC
[tomcat] branch 8.5.x updated: Fix HEAD tests when running on Java 19+
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new 5edc1d5373 Fix HEAD tests when running on Java 19+
5edc1d5373 is described below
commit 5edc1d5373a4a49e32cc11f59b3ec7ad0c8bd42b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed May 18 11:34:01 2022 +0100
Fix HEAD tests when running on Java 19+
---
.../servlet/http/HttpServletDoHeadBaseTest.java | 44 +++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/test/javax/servlet/http/HttpServletDoHeadBaseTest.java b/test/javax/servlet/http/HttpServletDoHeadBaseTest.java
index b93b749583..9a75d87260 100644
--- a/test/javax/servlet/http/HttpServletDoHeadBaseTest.java
+++ b/test/javax/servlet/http/HttpServletDoHeadBaseTest.java
@@ -35,6 +35,7 @@ import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.TomcatBaseTest;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.collections.CaseInsensitiveKeyMap;
+import org.apache.tomcat.util.compat.JreCompat;
/*
* Split into multiple tests as a single test takes so long it impacts the time
@@ -133,9 +134,50 @@ public class HttpServletDoHeadBaseTest extends TomcatBaseTest {
this.explicitFlush = explicitFlush;
}
+ @SuppressWarnings("removal")
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.setBufferSize(bufferSize);
+
+ int adjustedBufferSize = bufferSize;
+
+ if (Boolean.parseBoolean(getServletConfig().getInitParameter(LEGACY_DO_HEAD)) &&
+ useWriter && JreCompat.isJre19Available()) {
+ /*
+ * Using legacy HEAD handling with a Writer on Java 19+.
+ * HttpServlet wraps the response. The test is sensitive to
+ * buffer sizes. The size of the buffer HttpServlet uses varies
+ * with Java version. For the tests to pass the number of
+ * characters that can be written before the response is
+ * committed needs to be the same.
+ *
+ * Internally, Tomcat the response buffer is at least 8192
+ * bytes. When a Writer is used, an additional 8192 byte buffer
+ * is used for char -> byte.
+ *
+ * With Java <19, the char -> byte buffer is created as a 8192
+ * byte buffer which is consistent with the buffer Tomcat uses
+ * internally.
+ *
+ * With Java 19+, the char -> byte buffer is created as a 512
+ * byte buffer. Need to adjust the size of the response buffer
+ * to account for the smaller char -> byte buffer.
+ *
+ * This is why the legacy mode is problematic and the new
+ * approach of the container handling HEAD is better.
+ */
+
+ // Response buffer is always no smaller than 8192 bytes
+ if (adjustedBufferSize < 8192) {
+ adjustedBufferSize = 8192;
+ }
+
+ // Adjust for smaller initial char -> byte buffer in Java 19+
+ // 8192 initial size in Java <19
+ // 512 initial size in Java 19+
+ adjustedBufferSize = adjustedBufferSize + 8192 - 512;
+ }
+
+ resp.setBufferSize(adjustedBufferSize);
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8");
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org