Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-5772

LoadableDetachableModel caches null value if load() fails, bug in getObject() {attached = true;}

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.4.23, 6.18.0, 7.0.0-M4
    • Fix Version/s: 7.0.0-M5
    • Component/s: wicket

      Description

      If you have a LoadableDetachableModel whose load() operation fails at an instance, the LoadableDetachableModel will cache null value because

      getObject() method sets attached = true; before load() invocation has returned.

      This results in methods trusting LoadableDetachableModel using the null value for their operations which is logically incorrect as null might not be a legal value at all. Such behavior would result in unexpected difficult-to-debug behavior in depending components.

      Easy fix:
      Move:
      attached = true;
      after line:
      transientModelObject = load();

      Test case:

      /**

      • LoadableDetachableModel must not return null as an attached value if load()
      • fails.
        */
        public void testWhenLoadFails() {
        final LoadableDetachableModel<Void> loadableDetachableModel = new LoadableDetachableModel<Void>() {
        /**
      • @see org.apache.wicket.model.LoadableDetachableModel#load()
        */
        @Override
        protected Void load() { throw new UnsupportedOperationException("Let's assume this fails for some reason."); }

        };
        try

        { loadableDetachableModel.getObject(); fail(UnsupportedOperationException.class + " expected."); }

        catch (final UnsupportedOperationException e)

        { LoggerFactory.getLogger(LoadableDetachableModel.class).debug("Expected behavior due to " + UnsupportedOperationException.class); }

        try { assertNotSame(LoadableDetachableModel.class + " should not return null if it's load() has failed\n", null, loadableDetachableModel.getObject()); } catch (final UnsupportedOperationException e) { LoggerFactory.getLogger(LoadableDetachableModel.class).debug("Expected behavior due to " + UnsupportedOperationException.class); }

        }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                svenmeier Sven Meier
                Reporter:
                mmakundi Martin Terra
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 10m
                  10m
                  Remaining:
                  Remaining Estimate - 10m
                  10m
                  Logged:
                  Time Spent - Not Specified
                  Not Specified