This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch 1.X
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/1.X by this push:
new be3bfa34 Resolve column name in ResultSetIterator.set (1.X) (#428)
be3bfa34 is described below
commit be3bfa34d3bdeba6dc92c1213e975bd539457cd1
Author: Naveed Khan <[email protected]>
AuthorDate: Fri Jul 24 12:31:20 2026 +0000
Resolve column name in ResultSetIterator.set (1.X) (#428)
port of #426. the read path resolves the dyna-property name to the real
column name via getColumnName, but set passed the raw name to updateObject, so
with the default lowerCase a mixed-case column update targeted the wrong
column. Same fix and regression test as master, adapted to the JUnit 3 style on
this branch.
---
.../commons/beanutils/ResultSetIterator.java | 2 +-
.../commons/beanutils/DynaResultSetTest.java | 25 ++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/beanutils/ResultSetIterator.java
b/src/main/java/org/apache/commons/beanutils/ResultSetIterator.java
index 0ed83bca..82288d0f 100644
--- a/src/main/java/org/apache/commons/beanutils/ResultSetIterator.java
+++ b/src/main/java/org/apache/commons/beanutils/ResultSetIterator.java
@@ -264,7 +264,7 @@ public class ResultSetIterator implements DynaBean,
Iterator<DynaBean> {
throw new IllegalArgumentException(name);
}
try {
- dynaClass.getResultSet().updateObject(name, value);
+
dynaClass.getResultSet().updateObject(dynaClass.getColumnName(name), value);
} catch (final SQLException e) {
throw new IllegalArgumentException("set(" + name + "):
SQLException: " + e, e);
}
diff --git a/src/test/java/org/apache/commons/beanutils/DynaResultSetTest.java
b/src/test/java/org/apache/commons/beanutils/DynaResultSetTest.java
index 0fb49eeb..f43ff2e7 100644
--- a/src/test/java/org/apache/commons/beanutils/DynaResultSetTest.java
+++ b/src/test/java/org/apache/commons/beanutils/DynaResultSetTest.java
@@ -18,7 +18,10 @@
package org.apache.commons.beanutils;
import java.math.BigDecimal;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Iterator;
+import java.util.concurrent.atomic.AtomicReference;
import junit.framework.TestCase;
@@ -123,6 +126,28 @@ public class DynaResultSetTest extends TestCase {
}
+ /**
+ * With the default {@code lowerCase} option the property name differs
from the real column name, and the read path resolves it through
+ * {@code getColumnName}. Verify that {@code set} resolves it the same
way, so the update targets the real column name and not the lower-cased property
+ * name.
+ */
+ public void testSetUsesColumnName() throws Exception {
+
+ final AtomicReference<String> updatedColumn = new
AtomicReference<String>();
+ final ResultSet resultSet = TestResultSet.createProxy(new
TestResultSet() {
+ @Override
+ public void updateObject(final String columnName, final Object
value) throws SQLException {
+ updatedColumn.set(columnName);
+ }
+ });
+ final ResultSetDynaClass rsdc = new ResultSetDynaClass(resultSet);
+ final DynaBean row = rsdc.iterator().next();
+ row.set("stringproperty", "new value");
+ assertEquals("update targets the real column name",
+ "stringProperty", updatedColumn.get());
+
+ }
+
public void testIteratorCount() {
final Iterator<?> rows = dynaClass.iterator();