You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jeremy Tonghao Sun (Jira)" <ji...@apache.org> on 2026/01/09 05:15:00 UTC

[jira] (LANG-1711) Modify ReflectionToStringBuilder to use trySetAccessible and not throw exceptions

    [ https://issues.apache.org/jira/browse/LANG-1711 ]


    Jeremy Tonghao Sun deleted comment on LANG-1711:
    ------------------------------------------

was (Author: jeremysun):
This change makes ReflectionDiffBuilder skip fields that cannot be accessed via reflection

instead of failing fast with an exception.

 

Previously, if reflective access to a field was denied (for example due to Java 9+ module

restrictions or security constraints), the diff process would abort entirely. This prevented

producing a partial diff even when most fields were accessible.

 

The implementation is limited to appendFields(...), where reflection access failures are

caught and ignored. This covers IllegalAccessException on Java 8 as well as runtime reflection

failures on newer Java versions. No public APIs were changed.

 

This keeps full Java 8 compatibility while improving robustness on restricted environments.

> Modify ReflectionToStringBuilder to use trySetAccessible and not throw exceptions
> ---------------------------------------------------------------------------------
>
>                 Key: LANG-1711
>                 URL: https://issues.apache.org/jira/browse/LANG-1711
>             Project: Commons Lang
>          Issue Type: Improvement
>            Reporter: Oksana
>            Priority: Major
>
> org.apache.commons.lang3.builder.ReflectionToStringBuilder#appendFieldsIn uses following method
> _AccessibleObject.setAccessible(fields, true);_
> It will throw exception when it is not possible to perform action. I think, better approach - just to skip not accessible fields and report only accessible once. Since Java 9 there is a method trySetAccessible for that.
> [https://github.com/apache/commons-lang/pull/1102]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)