garydgregory commented on PR #1509: URL: https://github.com/apache/commons-lang/pull/1509#issuecomment-7256595426
Hello @crowmagnumb Thank you for identifying and reproducing the problem. The bug is real, but the proposed fix leaves important cases unresolved. I opened [#1898](https://github.com/apache/commons-lang/pull/1898) to address those gaps and integrate the fix with the current implementation. There are three substantive reasons for replacing the original approach: - **`Class.isEnum()` does not recognize every enum value.** A constant with its own class body has an anonymous subclass as its runtime class, so `value.getClass().isEnum()` returns `false`. Such values still enter reflective formatting and can trigger the original exception. The replacement uses `Enum.class.isAssignableFrom(clazz)` to cover both ordinary constants and constants with class bodies. - **The multiline style also needs the fix.** `MultilineRecursiveToStringStyle` overrides `appendDetail()` and performs its own recursive formatting. Changing only the superclass’s method leaves that path unfixed. The replacement makes both styles use the shared filtering policy and removes redundant checks. - **The exclusion must also apply to traversal bookkeeping.** In the current code, preventing reflection only inside `appendDetail()` is insufficient: enum values can still be marked as visited or subjected to the nested-object output limit. Putting the exclusion in `accept()` keeps formatting and traversal decisions consistent. The original test covers one plain enum in a nested object. The replacement adds regression cases, including custom `toString()` implementations, constants with class bodies, repeated references, containers, summaries, output limits, and exact multiline formatting. You are credited in `changes.xml`; closing. -- 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]
