simpleqt opened a new pull request, #416:
URL: https://github.com/apache/commons-dbutils/pull/416
`GenerousBeanProcessor` maps columns to properties itself and only compared
the column name, and the column name with the underscores removed, against the
property name. It never looked at the `@Column` annotation that `BeanProcessor`
honors, so an annotated column was ignored and another column that happened to
match the property name was read instead.
```java
public class Bean {
private String stockCode;
@Column(name = "inv_stock")
public String getStockCode() { return stockCode; }
public void setStockCode(String v) { stockCode = v; }
}
```
With a result set whose only column is `INV_STOCK`:
```java
new GenerousBeanProcessor().toBean(rs, Bean.class).getStockCode(); // null
```
`BeanProcessor` returns `ACME` for the same result set. When the result set
has both `INV_STOCK` and `STOCK_CODE`, `GenerousBeanProcessor` reads
`STOCK_CODE`, and which column wins depends on the column order, while
`BeanProcessor` always reads the annotated `INV_STOCK`.
**Fix**
The annotation lookup is moved into a new protected
`BeanProcessor.getPropertyColumnName(PropertyDescriptor)` and both processors
use it. `GenerousBeanProcessor` now tries the annotated name first and falls
back to the generous name, so the annotation is honored and no other column is
taken for it. A `@Column` without a name still falls back to the property name,
as before.
**Tests**
Three tests in `GenerousBeanProcessorTest`, using the
`MockResultSetMetaData` idiom already used there:
- `testMapColumnsToPropertiesHonorsColumnAnnotation`
- `testMapColumnsToPropertiesPrefersTheColumnAnnotation`
- `testMapColumnsToPropertiesUnnamedColumnAnnotation`
On the parent commit the first two fail:
```
org.opentest4j.AssertionFailedError: expected: <0> but was: <-1>
```
**Verification**
```
mvn -B -ntp verify
Tests run: 526, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
```
The behaviour was also checked against a real H2 in-memory database through
`QueryRunner` and `BeanHandler`: the annotated bean is populated from the
annotated column, for both processors, in either column order. `changes.xml`
has an entry in the 1.9.0 FIX section.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]