jadhavgaurav commented on PR #1798:
URL: https://github.com/apache/commons-lang/pull/1798#issuecomment-5889248536
Thanks for looking, and understood that the ticket is old. Here is the
concrete behavior the patch changes, so you can judge whether it is worth
having.
With a `ReflectionToStringBuilder` using `RecursiveToStringStyle`,
`setExcludeFieldNames` currently applies only to the top-level object:
```java
Person p = new Person();
p.job = new Job();
p.job.title = "Manager";
ReflectionToStringBuilder b = new ReflectionToStringBuilder(p, new
RecursiveToStringStyle());
b.setExcludeFieldNames("title");
b.toString();
```
Before: `...job=Job[title=Manager]...` (the excluded field is still printed)
After: `...job=Job[]...`
The cause is that `RecursiveToStringStyle.appendDetail()` renders a nested
object through the static `ReflectionToStringBuilder.toString(value, style)`,
which builds a fresh builder that knows nothing about the outer builder's
exclusions. So an exclusion meant to keep a field out of the output (a password
field, for example) is honored on the outer object and silently ignored on
nested ones.
`RecursiveToStringStyleTest#testExcludeFieldNamesAppliesToNestedObjects`
fails without the change and passes with it.
If you would rather not change this behavior, I understand and am fine with
the PR being closed. If it is wanted, I can also simplify the approach (for
example, avoid the per-thread stack) if you prefer something smaller.
--
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]