title: java.lang.IllegalArgumentException: Comparison method violates its general contract! in Spring Rest Template
body: <p>I am facing a weird issue while calling a REST url using Spring's RestTemplate.I am using Spring Boot.</p>
  
  <p>The error is occurring only after approx <strong>10 to 15 successful calls</strong> and thereafter <strong>erratically</strong>. I can smoothly exchange data before the error, in the first 1 to 15 calls approx. Url is like <code>someresturl/param1/param2/param3</code>.</p>
  
  <pre><code>     public ResponseEntity&lt;String&gt; callRestUrl(CustomReqClass req) {
  
          restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
              restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
              StringBuilder url = new StringBuilder("someresturl");
  
     finishTaskUrl.append("/").append(param1).append("/").append(param2).append("/").append(param3);        
              ResponseEntity&lt;String&gt; response = null;
  
              HttpEntity&lt;CustomReqClass&gt; request = new HttpEntity&lt;CustomReqClass&gt;(req, getHTTPHeaders());
  
         try {
  
                //first approach
                  response = restTemplate.postForEntity(url.toString(), request, String.class, Collections.&lt;String, String&gt;emptyMap());
  
                 //second approach
                 response = restTemplate.exchange(url.toString(), HttpMethod.POST, request, String.class);
  
              } catch (Exception e) {
                  LOGGER.info("Error calling url" + e);
              }
              return response;
          }
  
     public MultiValueMap&lt;String, String&gt; getHTTPHeaders() {
      MultiValueMap&lt;String, String&gt; headers = new LinkedMultiValueMap&lt;String, String&gt;();
      headers.add("Authorization", "Basic authabcdxyz");
      headers.add("Content-Type", "application/json");
      return headers;
  }
  </code></pre>
  
  <p>Here I am autowiring restTemplate object in the class where I am using this.
  I have tried both the above methods <strong>postForEntity</strong> and <strong>exchange</strong> of Rest template. Error is occurring for both.</p>
  
  <p>The exception I am getting after first few successful attempts:</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Comparison method violates its general contract!</p>
  </blockquote>
  
  <p>As an additional thought, the above piece of code is being scheduled by Spring Scheduler mechanism. Is it possible internal threading used in scheduler is causing this issue?</p>