This is an automated email from the ASF dual-hosted git repository.
markt-asf 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 40d459f78f Align FilterDef with SefvletDef for asyncSupported
40d459f78f is described below
commit 40d459f78f32a4582d125cab465925d18fbb9b39
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Nov 11 19:50:12 2026 +0000
Align FilterDef with SefvletDef for asyncSupported
---
TODO.md | 10 --------
.../catalina/core/ApplicationFilterChain.java | 6 +++--
.../tomcat/util/descriptor/web/FilterDef.java | 25 ++++++--------------
.../tomcat/util/descriptor/web/ServletDef.java | 6 ++++-
.../apache/tomcat/util/descriptor/web/WebXml.java | 12 ++++++----
.../startup/TestContextConfigAnnotation.java | 3 +--
.../tomcat/util/descriptor/web/TestFilterDef.java | 27 +++++-----------------
7 files changed, 30 insertions(+), 59 deletions(-)
diff --git a/TODO.md b/TODO.md
index 101fa15a2f..32bd52f87f 100644
--- a/TODO.md
+++ b/TODO.md
@@ -930,16 +930,6 @@ These are bugs, correctness issues, or missing
functionality that may affect pro
---
-### 88. Annotation Test Type Inconsistency (1 item)
-
-| # | File:Line | Description | Fix Idea | Effort | Difficulty |
-|---|-----------|-------------|----------|--------|------------|
-| 88.1 | `TestContextConfigAnnotation.java:243` | `servletDef` is Boolean,
`FilterDef` is String - inconsistent | Investigate why the types differ. If
it's a bug, fix the annotation processing. If intentional, document. | 0.5-1
day | Low |
-
-**Total estimated effort: 0.5-1 day, Low difficulty**
-
----
-
### 89. Example WebSocket Drawboard (5 items)
| # | File:Line | Description | Fix Idea | Effort | Difficulty |
diff --git a/java/org/apache/catalina/core/ApplicationFilterChain.java
b/java/org/apache/catalina/core/ApplicationFilterChain.java
index 354cc37b27..58bd9cbb61 100644
--- a/java/org/apache/catalina/core/ApplicationFilterChain.java
+++ b/java/org/apache/catalina/core/ApplicationFilterChain.java
@@ -104,8 +104,9 @@ public final class ApplicationFilterChain implements
FilterChain {
ApplicationFilterConfig filterConfig = filters[pos++];
try {
Filter filter = filterConfig.getFilter();
+ Boolean asyncSupported =
filterConfig.getFilterDef().getAsyncSupported();
- if (request.isAsyncSupported() &&
!(filterConfig.getFilterDef().getAsyncSupportedBoolean())) {
+ if (request.isAsyncSupported() && (asyncSupported == null ||
!asyncSupported.booleanValue())) {
request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR,
Boolean.FALSE);
}
filter.doFilter(request, response, this);
@@ -240,7 +241,8 @@ public final class ApplicationFilterChain implements
FilterChain {
public void findNonAsyncFilters(Set<String> result) {
for (int i = 0; i < n; i++) {
ApplicationFilterConfig filter = filters[i];
- if (!(filter.getFilterDef().getAsyncSupportedBoolean())) {
+ Boolean asyncSupported = filter.getFilterDef().getAsyncSupported();
+ if (asyncSupported == null || !asyncSupported.booleanValue()) {
result.add(filter.getFilterClass());
}
}
diff --git a/java/org/apache/tomcat/util/descriptor/web/FilterDef.java
b/java/org/apache/tomcat/util/descriptor/web/FilterDef.java
index 4e7f028215..2f6a924a80 100644
--- a/java/org/apache/tomcat/util/descriptor/web/FilterDef.java
+++ b/java/org/apache/tomcat/util/descriptor/web/FilterDef.java
@@ -235,14 +235,14 @@ public class FilterDef implements Serializable {
/**
* The async-supported setting for this filter.
*/
- private String asyncSupported = null;
+ private Boolean asyncSupported = null;
/**
* Returns the async-supported setting for this filter.
*
* @return The async-supported value
*/
- public String getAsyncSupported() {
+ public Boolean getAsyncSupported() {
return asyncSupported;
}
@@ -254,22 +254,11 @@ public class FilterDef implements Serializable {
* @param asyncSupported The async-supported value
*/
public void setAsyncSupported(String asyncSupported) {
- this.asyncSupported = asyncSupported;
- asyncSupportedBoolean = "true".equalsIgnoreCase(asyncSupported);
- }
-
- /**
- * The async-supported boolean setting for this filter.
- */
- private boolean asyncSupportedBoolean = false;
-
- /**
- * Returns whether async processing is supported for this filter.
- *
- * @return True if async is supported, false otherwise
- */
- public boolean getAsyncSupportedBoolean() {
- return asyncSupportedBoolean;
+ if (asyncSupported == null) {
+ this.asyncSupported = null;
+ } else {
+ this.asyncSupported = Boolean.valueOf(asyncSupported);
+ }
}
// --------------------------------------------------------- Public Methods
diff --git a/java/org/apache/tomcat/util/descriptor/web/ServletDef.java
b/java/org/apache/tomcat/util/descriptor/web/ServletDef.java
index e5a65be7a9..2ae2b7fadf 100644
--- a/java/org/apache/tomcat/util/descriptor/web/ServletDef.java
+++ b/java/org/apache/tomcat/util/descriptor/web/ServletDef.java
@@ -363,7 +363,11 @@ public class ServletDef implements Serializable {
* @param asyncSupported whether async is supported as a string
*/
public void setAsyncSupported(String asyncSupported) {
- this.asyncSupported = Boolean.valueOf(asyncSupported);
+ if (asyncSupported == null) {
+ this.asyncSupported = null;
+ } else {
+ this.asyncSupported = Boolean.valueOf(asyncSupported);
+ }
}
diff --git a/java/org/apache/tomcat/util/descriptor/web/WebXml.java
b/java/org/apache/tomcat/util/descriptor/web/WebXml.java
index 4e63ef8454..e7eae2acc6 100644
--- a/java/org/apache/tomcat/util/descriptor/web/WebXml.java
+++ b/java/org/apache/tomcat/util/descriptor/web/WebXml.java
@@ -2481,11 +2481,13 @@ public class WebXml {
}
private static boolean mergeFilter(FilterDef src, FilterDef dest, boolean
failOnConflict) {
- if (dest.getAsyncSupported() == null) {
- dest.setAsyncSupported(src.getAsyncSupported());
- } else if (src.getAsyncSupported() != null) {
- if (failOnConflict &&
!src.getAsyncSupported().equals(dest.getAsyncSupported())) {
- return false;
+ if (src.getAsyncSupported() != null) {
+ if (dest.getAsyncSupported() == null) {
+ dest.setAsyncSupported(src.getAsyncSupported().toString());
+ } else {
+ if (failOnConflict &&
!src.getAsyncSupported().equals(dest.getAsyncSupported())) {
+ return false;
+ }
}
}
diff --git a/test/org/apache/catalina/startup/TestContextConfigAnnotation.java
b/test/org/apache/catalina/startup/TestContextConfigAnnotation.java
index f52b8a4f3e..69525275b6 100644
--- a/test/org/apache/catalina/startup/TestContextConfigAnnotation.java
+++ b/test/org/apache/catalina/startup/TestContextConfigAnnotation.java
@@ -240,8 +240,7 @@ public class TestContextConfigAnnotation {
Assert.assertEquals("DisplayName", fdef.getDisplayName());
Assert.assertEquals("LargeIcon", fdef.getLargeIcon());
Assert.assertEquals("SmallIcon", fdef.getSmallIcon());
- // FIXME: Strange why servletDef is Boolean and FilterDef is String?
- Assert.assertEquals("true", fdef.getAsyncSupported());
+ Assert.assertTrue(fdef.getAsyncSupported().booleanValue());
String[] dis = filterMap.getDispatcherNames();
Assert.assertEquals(2, dis.length);
diff --git a/test/org/apache/tomcat/util/descriptor/web/TestFilterDef.java
b/test/org/apache/tomcat/util/descriptor/web/TestFilterDef.java
index 810e8de837..b9b9f68546 100644
--- a/test/org/apache/tomcat/util/descriptor/web/TestFilterDef.java
+++ b/test/org/apache/tomcat/util/descriptor/web/TestFilterDef.java
@@ -42,42 +42,27 @@ public class TestFilterDef {
"test", filterDef.getFilterName());
}
- @Test
- public void testAsyncSupportedDefaultsToFalse() {
- // The specification default is that a filter does not support async
- // processing and every other async-supported default in the container
- // is false. This matters in particular for filters registered
- // dynamically via ServletContext.addFilter() which do not pass through
- // the ContextConfig normalisation of the descriptor value.
- FilterDef filterDef = new FilterDef();
- Assert.assertNull(filterDef.getAsyncSupported());
- Assert.assertFalse(filterDef.getAsyncSupportedBoolean());
- }
-
@Test
public void testSetAsyncSupported() {
FilterDef filterDef = new FilterDef();
filterDef.setAsyncSupported("true");
- Assert.assertTrue(filterDef.getAsyncSupportedBoolean());
+ Assert.assertTrue(filterDef.getAsyncSupported().booleanValue());
filterDef.setAsyncSupported("TRUE");
- Assert.assertTrue(filterDef.getAsyncSupportedBoolean());
+ Assert.assertTrue(filterDef.getAsyncSupported().booleanValue());
filterDef.setAsyncSupported("false");
- Assert.assertFalse(filterDef.getAsyncSupportedBoolean());
+ Assert.assertFalse(filterDef.getAsyncSupported().booleanValue());
// Only "true" enables async support. Anything else, including null
// and invalid values such as "yes", is not supported which matches
- // the handling by ServletDef and by Boolean. The string value is
- // stored as-is since WebXml.mergeFilter() and the ContextConfig
- // normalisation of the descriptor value operate on it.
+ // the handling by ServletDef and by Boolean.
filterDef.setAsyncSupported("yes");
- Assert.assertEquals("yes", filterDef.getAsyncSupported());
- Assert.assertFalse(filterDef.getAsyncSupportedBoolean());
+ Assert.assertFalse(filterDef.getAsyncSupported().booleanValue());
filterDef.setAsyncSupported(null);
- Assert.assertFalse(filterDef.getAsyncSupportedBoolean());
+ Assert.assertNull(filterDef.getAsyncSupported());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]