Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-17550

Equals checks to MediaType.ALL should not be affected the presence of parameters

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.3.20, 5.1.3
    • Fix Version/s: 5.1.4
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      I discovered this while trying to create an annotation for non-json Controllers with @RequestMapping(accept="!application/json")
      When the RequestMappingInfo invokes

      ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);
      
      

      the code checks if the accepted media type contains MEDIA_ALL. But in my case the header contained a quality argument:

      text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
      
      

      and, after parsing, resulted in a mediatype */* with quality 0.8 this failed to match with the check at the end of the ProducesRequestCondition

      		else if (acceptedMediaTypes.contains(MediaType.ALL)) {
      			return EMPTY_CONDITION;
      		}
      
      

      From what I see there are multiple places where there is an attempt to match MediaType ignoring the fact that they might have a quality on them.
      Either there should be an overload of .equals and .hashcode to ignore the quality, or create an ad-hoc method to compare them without considering the quality and use it every time they check for presence inside a collection

        Attachments

          Activity

            People

            • Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              r_litto Raffaele Litto
              Last updater:
              Spring Issuemaster
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                47 weeks, 5 days ago