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

[JENKINS-64390] make FieldUtils behave as it used to #5105

Merged
merged 2 commits into from
Dec 13, 2020

Conversation

jtnord
Copy link
Member

@jtnord jtnord commented Dec 9, 2020

acegi FieldUtils used to silently fail when you tried to set a field that was both public and final

Whilst it seems silly to do that (the code was obviously a no-op) I observed a breakage in a plugin (test code) that was doing exactly that. seems like there is a possibility that some production code may exist that also was doing this that would now be broken, so make the code also silently fail for that case.

See JENKINS-64390.

Proposed changelog entries

  • FieldUtils now silently fails to set public final fields again.

Proposed upgrade guidelines

N/A

Submitter checklist

  • (If applicable) Jira issue is well described
  • Changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developer, depending on the change). Examples
    • Fill-in the Proposed changelog entries section only if there are breaking changes or other changes which may require extra steps from users during the upgrade
  • Appropriate autotests or explanation to why this change has no tests
  • For dependency updates: links to external changelogs and, if possible, full diffs

Desired reviewers

@jglick

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least 2 approvals for the pull request and no outstanding requests for change
  • Conversations in the pull request are over OR it is explicit that a reviewer does not block the change
  • Changelog entries in the PR title and/or Proposed changelog entries are correct
  • Proper changelog labels are set so that the changelog can be generated automatically
  • If the change needs additional upgrade steps from users, upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the PR title. (example)
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@jtnord jtnord added the bug For changelog: Minor bug. Will be listed after features label Dec 9, 2020
@jtnord jtnord requested review from a team and jglick December 9, 2020 18:05
assertThrows(Exception.class, () -> FieldUtils.setProtectedFieldValue("bogus", sut, "whatever"));
}

class InnerClassWithPublicFinalField {
Copy link
Member Author

Choose a reason for hiding this comment

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

this behaved differently with the initial acegi-rewrite if it was public

Co-authored-by: Jesse Glick <jglick@cloudbees.com>
@jtnord jtnord added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Dec 10, 2020
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

LGTM. I rather prefer the new behavior, but regression is a regression

@@ -40,8 +42,14 @@ public static Object getProtectedFieldValue(String protectedField, Object object

public static void setProtectedFieldValue(String protectedField, Object object, Object newValue) {
try {
org.apache.commons.lang.reflect.FieldUtils.writeField(object, protectedField, newValue, true);
} catch (IllegalAccessException x) {
// acgegi would silently fail to write to final fields
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// acgegi would silently fail to write to final fields
// acegi would silently fail to write to final fields

@jglick
Copy link
Member

jglick commented Dec 10, 2020

rather prefer the new behavior

Well the whole class is deprecated, so the sole criterion is compatibility.

@timja timja merged commit f7884d3 into jenkinsci:master Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
5 participants