Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-959

FieldUtils write methods do not write to final fields.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.2.1
    • Review Patch
    • lang.reflect.*
    • None

    Description

      I have a use case where I need to use reflection to set a public static final Object.

      This does not work with our FieldUtils class because the "forceAccess" argument is only used to deal with field visibility by calling Field#setAccessible(boolean)

      Q1: Should "forceAccess" be expanded to remove the final modifier? Or:
      Q2: Should we add another boolean parameter "forceWrite" to remove the FINAL modifier?

      I like Q1.

      Q3: The Accessible flag is NOT reset if changed after a write! I think it should be. Thoughts?

      The attached patch implements this BUT does not fix failing tests that expect writes to fail on final fields. I left the tests failing to show clearly which ones fail so we can discuss if:

      • this fixes a bug,
      • is an improvement acceptable for the next release
      • or breaks too much for the next release

      Discuss here or on the ML.

      Thank you.

      Attachments

        1. LANG-959.diff
          9 kB
          Gary D. Gregory

        Issue Links

          Activity

            People

              ggregory Gary D. Gregory
              ggregory Gary D. Gregory
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: