Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3599

Struts2 ignores 'final' modifier when backing form onto field

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Resolved
    • 2.1.6
    • None
    • Core Actions
    • None

    Description

      I had a bean and nested enum defined like

      public class SomeBean {
      private Type type;
      // getters+setters for type
      public static enum Type {
      UNSET(0),
      USER(1),
      GROUP(2);
      public final short code;
      private Type(short code)

      { this.code = code; }

      }
      }

      We accidentally included the final field 'code' as the name of a field on a form that was backed by Struts. e.g. something like:

      <s:select name="someBeanInstance.type.code" ... />

      When this field was submitted, the final field 'code' was updated on the enum to match the value picked in the select box. This caused a huge amount of confusion for a time, as this field is marked final and so shouldn't ever be updated... presumably Struts is using reflection to bypass the JVM enforcement on finality?

      Fix would be to check a public field isn't marked final, before backing a form onto it.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jonliss Jon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: