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

Return Optional<T> from RequestCycle.find(Class<T>)

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 8.0.0-M1
    • Fix Version/s: 8.0.0-M1
    • Component/s: wicket
    • Labels:
      None

      Description

      RequestCycle.find(Class<T>) is mostly used to get the current AjaxRequestTarget.
      Since the returned reference might be null (in case of a non-Ajax request), it would be better to return an Optional<AjaxRequestHandler>.

        Issue Links

          Activity

          Hide
          svenmeier Sven Meier added a comment -

          Actually just changing the return type of #find(Class) might lead to unnoticed regressions.

          The following if-cause will compile happily, but lead to a false result:

          if (RequestCycle.get().find(AjaxRequestTarget.class) == null) {
              // executed for non-ajax-request in Wicket 7
              // never executed in Wicket 8
              ...
          }
          

          IMHO deprecating the old method and introducing a new one will be easier for migration.

          Show
          svenmeier Sven Meier added a comment - Actually just changing the return type of #find(Class) might lead to unnoticed regressions. The following if-cause will compile happily, but lead to a false result: if (RequestCycle.get().find(AjaxRequestTarget.class) == null ) { // executed for non-ajax-request in Wicket 7 // never executed in Wicket 8 ... } IMHO deprecating the old method and introducing a new one will be easier for migration.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit fc92b5d5d892444106c3b47489e1b06a908e70dc in wicket's branch refs/heads/master from Sven Meier
          [ https://git-wip-us.apache.org/repos/asf?p=wicket.git;h=fc92b5d ]

          WICKET-6189 RequestCycle.find() returns Optional now

          Show
          jira-bot ASF subversion and git services added a comment - Commit fc92b5d5d892444106c3b47489e1b06a908e70dc in wicket's branch refs/heads/master from Sven Meier [ https://git-wip-us.apache.org/repos/asf?p=wicket.git;h=fc92b5d ] WICKET-6189 RequestCycle.find() returns Optional now
          Hide
          svenmeier Sven Meier added a comment -

          Having two methods (one returning ART and one Optional<ART) isn't something we want to support, so #find() return the optional now as powwowed.

          I've added a warning to the migration guide.

          Show
          svenmeier Sven Meier added a comment - Having two methods (one returning ART and one Optional<ART) isn't something we want to support, so #find() return the optional now as powwowed. I've added a warning to the migration guide.

            People

            • Assignee:
              svenmeier Sven Meier
              Reporter:
              svenmeier Sven Meier
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development