Suppress case variants of mapped names in isPropertySuppressed - #431
Conversation
The check compared the raw expression token, while the mapped-descriptor fallback it guards derives its accessor names from the capitalized property name, so a name differing only in the case of its first character resolved the same accessors and was still readable and writable.
There was a problem hiding this comment.
Pull request overview
This PR closes a suppression bypass for mapped properties where case-variants of the property token (e.g., MappedProperty(key) vs mappedProperty(key)) could still resolve the same mapped accessor pair and remain readable/writable despite suppression.
Changes:
- Align
isPropertySuppressed()withMappedPropertyDescriptor’s accessor-name derivation by comparing suppressed names on the same capitalized base form. - Expose
MappedPropertyDescriptor.capitalizePropertyName()at package scope to avoid duplication/drift in capitalization logic. - Add a regression test covering suppression of a mapped-property case variant.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/test/java/org/apache/commons/beanutils2/PropertyUtilsTest.java | Adds a regression test ensuring case-variants of suppressed mapped properties are also blocked. |
| src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java | Updates suppression check to compare on the capitalized base name used for mapped accessor resolution. |
| src/main/java/org/apache/commons/beanutils2/MappedPropertyDescriptor.java | Makes capitalizePropertyName package-private so the suppression logic can reuse the same derivation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return true; | ||
| if (introspector instanceof SuppressPropertiesBeanIntrospector) { | ||
| for (final String suppressed : ((SuppressPropertiesBeanIntrospector) introspector).getSuppressedProperties()) { | ||
| if (base.equals(MappedPropertyDescriptor.capitalizePropertyName(suppressed))) { |
There was a problem hiding this comment.
Good catch. getSuppressedProperties only guarantees the collection itself is non-null, so a null entry reached capitalizePropertyName and threw where the old Set.contains just never matched. Nulls are skipped in the loop now, with testCustomIntrospectionSuppressedMappedPropertyNullEntry covering it (NPEs without the guard).
|
@rootvector2 see copilot comments. If you ran copilot on your own branch before creating a PR, we could save some time here. |
SuppressPropertiesBeanIntrospector only rejects a null collection, so the suppressed set can hold null entries. Capitalizing them threw a NullPointerException where the previous Set.contains just never matched.
|
Addressed in |
|
@rootvector2 Thank you, merged 🚀 , please port to 1.x. |
|
Thanks for merging. Will do the 1.X port, though it's not a straight one: |
isPropertySuppressedcompares the raw expression token against the suppressed set, but the mapped-descriptor fallback it guards buildsget<Base>(String)/set<Base>(String, ?)fromMappedPropertyDescriptor.capitalizePropertyName(name), so any name that differs only in the case of its first character resolves the same accessor pair and is never matched by the check. WithmappedPropertysuppressed,mappedProperty(key)is blocked butMappedProperty(key)still reads and writes it, including throughBeanUtilsBean.populatewith a caller-supplied parameter map. Mapped accessors are never JavaBeans property descriptors, sodata.getDescriptor(name)is always null for them and this check is the only thing in front of the accessor.Comparing on the same capitalized base the descriptor derives keeps the guard and the descriptor from drifting apart again;
capitalizePropertyNamedrops to package-private for that. Found while re-auditing the suppression path from #413.PropertyUtilsTest.testCustomIntrospectionSuppressedMappedPropertyCaseVariantfails without the runtime change (MappedPropertystill resolves aMappedPropertyDescriptor) and passes with it. Fullmvndefault goal is green: 1284 tests, 0 failures.mvn; that'smvnon the command line by itself.