Uploaded image for project: 'Magnolia UI'
  1. Magnolia UI
  2. MGNLUI-3521

SelectFieldOptionDefinition comparison may throw NPE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Neutral Neutral
    • 5.3.12, 5.4.3
    • 5.4
    • forms
    • Basel 11
    • 8

      SelectFieldOptionDefinition's implementation of compareTo is fishy, and assumes the label field is never null, when in fact it might be.

      Example 1:
      It was first encountered in UI tests when adding a page at root level (maybe since MGNLSTK-1500, instance with STK + templating-samples). Basically, if the TemplateDefinition has no title set, then the TemplateSelectorFieldFactory (in pages app) may set the SelectFieldOptionDefinition's label to null.
      Note that super-factory SelectFieldFactory uses the value when label would otherwise be null. We may create a separate ticket to address that.

      Example 2, Jan says:

      you can run into it on creation of template when someone else is opening the selector ... so there is a race condition and we need to fix it in comparator

      Results in the following NPE:

      [INFO] [talledLocalContainer] Caused by: java.lang.NullPointerException
      [INFO] [talledLocalContainer] 	at info.magnolia.ui.form.field.definition.SelectFieldOptionDefinition.compareTo(SelectFieldOptionDefinition.java:100)
      [INFO] [talledLocalContainer] 	at info.magnolia.ui.form.field.definition.SelectFieldOptionDefinition.compareTo(SelectFieldOptionDefinition.java:43)
      [INFO] [talledLocalContainer] 	at java.util.ComparableTimSort.binarySort(ComparableTimSort.java:232)
      [INFO] [talledLocalContainer] 	at java.util.ComparableTimSort.sort(ComparableTimSort.java:176)
      [INFO] [talledLocalContainer] 	at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
      [INFO] [talledLocalContainer] 	at java.util.Arrays.sort(Arrays.java:472)
      [INFO] [talledLocalContainer] 	at java.util.Collections.sort(Collections.java:155)
      [INFO] [talledLocalContainer] 	at info.magnolia.ui.form.field.factory.SelectFieldFactory.buildOptions(SelectFieldFactory.java:138)
      [INFO] [talledLocalContainer] 	at info.magnolia.ui.form.field.factory.SelectFieldFactory.createFieldComponent(SelectFieldFactory.java:98)

        Acceptance criteria

              fgrilli Federico Grilli
              mgeljic Mikaël Geljić
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD

                    Estimated:
                    Original Estimate - 3d
                    3d
                    Remaining:
                    Time Spent - 1d Remaining Estimate - 2d
                    2d
                    Logged:
                    Time Spent - 1d Remaining Estimate - 2d
                    1d