Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor getValue method of ReflectionToStringBuilder & its subclasses to get the field value #1086

Conversation

shashankrnr32
Copy link

@shashankrnr32 shashankrnr32 commented Jul 24, 2023

Noticed this change recently which removed the usage of the method getValue to get the field value. Custom implementations of the getValue would not be used anymore.

@garydgregory

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shashankrnr32
Thank you for your PR!
This PR missing a unit test to avoid a future regression.

*
* @see java.lang.reflect.Field#get(Object)
*/
protected Object getValue(final Field field) throws IllegalAccessException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing IllegalAccessException?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As such, the method Reflection.getUnchecked does not throw any checked exception. By keeping this, i would either have to rethrow that in appendFieldsIn method or throw some RuntimeException so that i dont have to add checked exceptions to all the methods.

So, I removed it here. Open to suggestions

  1. Catch IllegalAccessException in the method appendFieldsIn and throw some RuntimeException
  2. Or rethrow the same exception. (Dont think this should be opted anyways)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @shashankrnr32
Thank you for your update.
This PR attempts to restore compatibility with the getValue() method but changes that method's definition and breaks compatibility differently. For example, if I have a subclass that overrides getValue() using the released signature, that subclass will no longer compile if this patch is applied. The test in this PR does not reflect that a subclass can throw IllegalAccessException in the getValue() method signature, so the test is not checking for full compatibility. See git master for a fix.

@shashankrnr32
Copy link
Author

Hi @shashankrnr32 Thank you for your PR! This PR missing a unit test to avoid a future regression.

@garydgregory Added ReflectionToStringBuilderCustomImplementationTest that overrides the getValue and modifies the generated field value by the base class. If this behaviour changes in the future, the test will break.

@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2023

Codecov Report

Merging #1086 (cb61a26) into master (60b55f2) will increase coverage by 0.13%.
Report is 118 commits behind head on master.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master    #1086      +/-   ##
============================================
+ Coverage     92.08%   92.22%   +0.13%     
- Complexity     7501     7552      +51     
============================================
  Files           195      197       +2     
  Lines         15720    15801      +81     
  Branches       2897     2923      +26     
============================================
+ Hits          14476    14572      +96     
+ Misses          670      659      -11     
+ Partials        574      570       -4     
Files Changed Coverage Δ
...mmons/lang3/builder/ReflectionToStringBuilder.java 92.92% <100.00%> (+1.01%) ⬆️

... and 13 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@garydgregory
Copy link
Member

@garydgregory
Copy link
Member

Closing, see the comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants