This is an automated email from the ASF dual-hosted git repository.
rmaucher 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 c7642ea856 Minor code review fixes
c7642ea856 is described below
commit c7642ea856d668804bdb5ebe99d82fb4caab84de
Author: remm <[email protected]>
AuthorDate: Tue Jun 2 10:55:38 2026 +0200
Minor code review fixes
Remove dead code in SetNextRule.
---
java/org/apache/naming/factory/BeanFactory.java | 2 +-
.../naming/factory/DataSourceLinkFactory.java | 4 ++
.../tomcat/util/digester/CallMethodRule.java | 3 +-
.../apache/tomcat/util/digester/CallParamRule.java | 12 +++--
.../apache/tomcat/util/digester/SetNextRule.java | 56 ----------------------
java/org/apache/tomcat/util/http/parser/Host.java | 13 +++--
.../apache/tomcat/util/http/parser/HttpParser.java | 5 +-
.../apache/tomcat/util/http/parser/Priority.java | 4 +-
.../org/apache/tomcat/util/http/parser/Ranges.java | 4 ++
.../tomcat/util/http/parser/StructuredField.java | 2 +-
10 files changed, 35 insertions(+), 70 deletions(-)
diff --git a/java/org/apache/naming/factory/BeanFactory.java
b/java/org/apache/naming/factory/BeanFactory.java
index e8bdc8569a..5fc25234de 100644
--- a/java/org/apache/naming/factory/BeanFactory.java
+++ b/java/org/apache/naming/factory/BeanFactory.java
@@ -126,7 +126,7 @@ public class BeanFactory implements ObjectFactory {
continue;
}
- value = (String) ra.getContent();
+ value = String.valueOf(ra.getContent());
Object[] valueArray = new Object[1];
diff --git a/java/org/apache/naming/factory/DataSourceLinkFactory.java
b/java/org/apache/naming/factory/DataSourceLinkFactory.java
index 605fbf0c08..966d2368e7 100644
--- a/java/org/apache/naming/factory/DataSourceLinkFactory.java
+++ b/java/org/apache/naming/factory/DataSourceLinkFactory.java
@@ -142,7 +142,11 @@ public class DataSourceLinkFactory extends
ResourceLinkFactory {
method = getConnection;
} else if ("unwrap".equals(method.getName())) {
return unwrap((Class<?>) args[0]);
+ } else if ("isWrapperFor".equals(method.getName())) {
+ Class<?> iface = (Class<?>) args[0];
+ return iface != null && iface.isInstance(ds);
}
+
try {
return method.invoke(ds, args);
} catch (Throwable t) {
diff --git a/java/org/apache/tomcat/util/digester/CallMethodRule.java
b/java/org/apache/tomcat/util/digester/CallMethodRule.java
index e2200350c3..e80c02fb26 100644
--- a/java/org/apache/tomcat/util/digester/CallMethodRule.java
+++ b/java/org/apache/tomcat/util/digester/CallMethodRule.java
@@ -123,11 +123,12 @@ public class CallMethodRule extends Rule {
this.targetOffset = targetOffset;
this.methodName = methodName;
- this.paramCount = paramCount;
if (paramTypes == null) {
+ this.paramCount = paramCount;
this.paramTypes = new Class[paramCount];
Arrays.fill(this.paramTypes, String.class);
} else {
+ this.paramCount = paramTypes.length;
this.paramTypes = new Class[paramTypes.length];
System.arraycopy(paramTypes, 0, this.paramTypes, 0,
this.paramTypes.length);
}
diff --git a/java/org/apache/tomcat/util/digester/CallParamRule.java
b/java/org/apache/tomcat/util/digester/CallParamRule.java
index f996ef9be9..c6da747243 100644
--- a/java/org/apache/tomcat/util/digester/CallParamRule.java
+++ b/java/org/apache/tomcat/util/digester/CallParamRule.java
@@ -131,8 +131,10 @@ public class CallParamRule extends Rule {
// if this CallParamRule is reused in subsequent nesting.
if (param != null) {
- Object[] parameters = (Object[]) digester.peekParams();
- parameters[paramIndex] = param;
+ Object obj = digester.peekParams();
+ if (obj instanceof Object[] parameters && parameters.length >
paramIndex) {
+ parameters[paramIndex] = param;
+ }
}
}
@@ -167,8 +169,10 @@ public class CallParamRule extends Rule {
public void end(String namespace, String name) {
if (bodyTextStack != null && !bodyTextStack.empty()) {
// what we do now is push one parameter onto the top set of
parameters
- Object[] parameters = (Object[]) digester.peekParams();
- parameters[paramIndex] = bodyTextStack.pop();
+ Object obj = digester.peekParams();
+ if (obj instanceof Object[] parameters && parameters.length >
paramIndex) {
+ parameters[paramIndex] = bodyTextStack.pop();
+ }
}
}
diff --git a/java/org/apache/tomcat/util/digester/SetNextRule.java
b/java/org/apache/tomcat/util/digester/SetNextRule.java
index 2bfd5292db..331ca4e32a 100644
--- a/java/org/apache/tomcat/util/digester/SetNextRule.java
+++ b/java/org/apache/tomcat/util/digester/SetNextRule.java
@@ -20,16 +20,9 @@ import org.apache.tomcat.util.IntrospectionUtils;
/**
- * <p>
* Rule implementation that calls a method on the (top-1) (parent) object,
passing the top object (child) as an
* argument. It is commonly used to establish parent-child relationships.
- * </p>
- * <p>
- * This rule now supports more flexible method matching by default. It is
possible that this may break (some) code
- * written against release 1.1.1 or earlier. See {@link #isExactMatch()} for
more details.
- * </p>
*/
-
public class SetNextRule extends Rule {
// ----------------------------------------------------------- Constructors
@@ -64,59 +57,10 @@ public class SetNextRule extends Rule {
*/
protected String paramType;
- /**
- * Should we use exact matching. Default is no.
- */
- protected boolean useExactMatch = false;
// --------------------------------------------------------- Public Methods
- /**
- * <p>
- * Is exact matching being used.
- * </p>
- * <p>
- * This rule uses <code>org.apache.commons.beanutils.MethodUtils</code> to
introspect the relevant objects so that
- * the right method can be called. Originally,
<code>MethodUtils.invokeExactMethod</code> was used. This matches
- * methods very strictly and so may not find a matching method when one
exists. This is still the behaviour when
- * exact matching is enabled.
- * </p>
- * <p>
- * When exact matching is disabled, <code>MethodUtils.invokeMethod</code>
is used. This method finds more methods
- * but is less precise when there are several methods with correct
signatures. So, if you want to choose an exact
- * signature you might need to enable this property.
- * </p>
- * <p>
- * The default setting is to disable exact matches.
- * </p>
- *
- * @return true iff exact matching is enabled
- *
- * @since Digester Release 1.1.1
- */
- public boolean isExactMatch() {
-
- return useExactMatch;
- }
-
- /**
- * <p>
- * Set whether exact matching is enabled.
- * </p>
- * <p>
- * See {@link #isExactMatch()}.
- * </p>
- *
- * @param useExactMatch should this rule use exact method matching
- *
- * @since Digester Release 1.1.1
- */
- public void setExactMatch(boolean useExactMatch) {
-
- this.useExactMatch = useExactMatch;
- }
-
/**
* Process the end of this element.
*
diff --git a/java/org/apache/tomcat/util/http/parser/Host.java
b/java/org/apache/tomcat/util/http/parser/Host.java
index 2bdd0b8a00..bfc5e53f75 100644
--- a/java/org/apache/tomcat/util/http/parser/Host.java
+++ b/java/org/apache/tomcat/util/http/parser/Host.java
@@ -99,11 +99,16 @@ public class Host {
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
- for (int i = off; i < off + len; i++) {
- // Want output in range 0 to 255, not -128 to 127
- cbuf[i] = (char) (bytes[pos++] & 0xFF);
+ if (pos < end) {
+ len = Math.min(len, end - pos);
+ for (int i = off; i < off + len; i++) {
+ // Want output in range 0 to 255, not -128 to 127
+ cbuf[i] = (char) (bytes[pos++] & 0xFF);
+ }
+ return len;
+ } else {
+ return -1;
}
- return len;
}
@Override
diff --git a/java/org/apache/tomcat/util/http/parser/HttpParser.java
b/java/org/apache/tomcat/util/http/parser/HttpParser.java
index 949d63353e..0e7735d552 100644
--- a/java/org/apache/tomcat/util/http/parser/HttpParser.java
+++ b/java/org/apache/tomcat/util/http/parser/HttpParser.java
@@ -640,7 +640,7 @@ public class HttpParser {
/**
* @return the number if digits were found, -1 if no data was found or if
data other than digits was found
*/
- static long readInteger(Reader input) throws IOException {
+ static int readInteger(Reader input) throws IOException {
String digits = readDigits(input);
if (digits.isEmpty()) {
@@ -687,6 +687,9 @@ public class HttpParser {
return null;
} else if (c == '\\') {
c = input.read();
+ if (c == -1) {
+ return null;
+ }
if (returnQuoted) {
result.append('\\');
}
diff --git a/java/org/apache/tomcat/util/http/parser/Priority.java
b/java/org/apache/tomcat/util/http/parser/Priority.java
index 7b40ff2e42..c1d8dc419f 100644
--- a/java/org/apache/tomcat/util/http/parser/Priority.java
+++ b/java/org/apache/tomcat/util/http/parser/Priority.java
@@ -104,7 +104,7 @@ public class Priority {
SfListMember urgencyListMember = dictionary.getDictionaryMember("u");
// If not an integer, ignore it
if (urgencyListMember instanceof SfInteger) {
- long urgency = ((SfInteger)
urgencyListMember).getVaue().longValue();
+ long urgency = ((SfInteger)
urgencyListMember).getValue().longValue();
// If out of range, ignore it
if (urgency > -1 && urgency < 8) {
result.setUrgency((int) urgency);
@@ -114,7 +114,7 @@ public class Priority {
SfListMember incrementalListMember =
dictionary.getDictionaryMember("i");
// If not a boolean, ignore it
if (incrementalListMember instanceof SfBoolean) {
- result.setIncremental(((SfBoolean)
incrementalListMember).getVaue().booleanValue());
+ result.setIncremental(((SfBoolean)
incrementalListMember).getValue().booleanValue());
}
return result;
diff --git a/java/org/apache/tomcat/util/http/parser/Ranges.java
b/java/org/apache/tomcat/util/http/parser/Ranges.java
index 4084ab2a71..d7e9fa6b2d 100644
--- a/java/org/apache/tomcat/util/http/parser/Ranges.java
+++ b/java/org/apache/tomcat/util/http/parser/Ranges.java
@@ -155,6 +155,10 @@ public class Ranges {
// Invalid range
return null;
}
+ if (end != -1 && start > end) {
+ // Invalid range: start must not be greater than end
+ return null;
+ }
entries.add(new Entry(start, end));
diff --git a/java/org/apache/tomcat/util/http/parser/StructuredField.java
b/java/org/apache/tomcat/util/http/parser/StructuredField.java
index c5072b354a..a050d7830c 100644
--- a/java/org/apache/tomcat/util/http/parser/StructuredField.java
+++ b/java/org/apache/tomcat/util/http/parser/StructuredField.java
@@ -552,7 +552,7 @@ public class StructuredField {
this.value = value;
}
- T getVaue() {
+ T getValue() {
return value;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]