Spring Framework
  1. Spring Framework
  2. SPR-10402

Request @RequestParam not enforced with empty values

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 3.2.2
    • Fix Version/s: 3.2.3, 4.0 M1
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      I have defined this method signature:

      @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_XML_VALUE,
        "application/json;charset=UTF-8" })
      public ResponseEntity<Object> searchProjects(@RequestParam(value = "q") String query,
        @RequestParam("attributes") String[] attributes,
        @RequestParam(value = "outputType", required = false, defaultValue = "hash") OutputType outputType)
        throws MissingServletRequestParameterException
      

      When I invoke this method either with:

      GET /rest?q&attributes=one
      

      or

      GET /rest?q=&attributes=one
      

      The query variable is always passed as empty string/null although its defined as required. MissingServletRequestParameterException is not thrown.

      I have attached a screenshot of the debugging session where one can inspect that case. I think the else if in lines 95 to 97 are incomplete.

        Issue Links

          Activity

          Hide
          Michael Osipov added a comment -

          Rossen, fine. Can we postpone this to 4.x with a refined logic to fill gaps like these?

          I will evaluate the org.springframework.beans.propertyeditors.StringTrimmerEditor class.

          Show
          Michael Osipov added a comment - Rossen, fine. Can we postpone this to 4.x with a refined logic to fill gaps like these? I will evaluate the org.springframework.beans.propertyeditors.StringTrimmerEditor class.
          Hide
          Michael Osipov added a comment -

          Unfortunately, situation remains as-is. I deploy a workaround in my controller:

          // Workaround for https://jira.springsource.org/browse/SPR-10402
          if (StringUtils.isEmpty(query))
            throw new MissingServletRequestParameterException("q", "String");
          if (ArrayUtils.isEmpty(attributes))
            throw new MissingServletRequestParameterException("attributes", "String[]");
          
          Show
          Michael Osipov added a comment - Unfortunately, situation remains as-is. I deploy a workaround in my controller: // Workaround for https://jira.springsource.org/browse/SPR-10402 if (StringUtils.isEmpty(query)) throw new MissingServletRequestParameterException( "q" , " String " ); if (ArrayUtils.isEmpty(attributes)) throw new MissingServletRequestParameterException( "attributes" , " String []" );
          Hide
          Stefan Gheorghiu added a comment -

          This bug is still there in 3.2.3.RELEASE. Rolling back to 3.2.2 helps. Please fix it in 3.2.4.

          Show
          Stefan Gheorghiu added a comment - This bug is still there in 3.2.3.RELEASE. Rolling back to 3.2.2 helps. Please fix it in 3.2.4.
          Hide
          Rossen Stoyanchev added a comment -

          I'm guessing you're referring to the bug as described in SPR-10584? It was fixed in 3.2.4.

          Show
          Rossen Stoyanchev added a comment - I'm guessing you're referring to the bug as described in SPR-10584 ? It was fixed in 3.2.4.
          Hide
          Stefan Gheorghiu added a comment -

          Exactly. I just used a wrong browser tab. Sorry for that.

          Show
          Stefan Gheorghiu added a comment - Exactly. I just used a wrong browser tab. Sorry for that.

            People

            • Assignee:
              Rossen Stoyanchev
              Reporter:
              Michael Osipov
              Last updater:
              Stefan Gheorghiu
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                35 weeks ago