title: Comparison method violates its general contract! when trying to send message to Websphere mq
body: <p>I am using spring jms to connect to Websphere MQ. I am trying to connect through localhost not using jndi info right now.</p>
  
  <pre><code>Connection names (all as an example): hostname: &lt;Websphere ip address&gt; http://localhost:9043
  given hostname 12.123.0.12
  
  In Resources-&gt;JMS-&gt;Queue connection Factories
  name: MQDemo
  JNDI name: MQDemo
  
  2 Queues:
  name: MQ.T11.UPDATE.REQUEST
  JNDI name: jms/MQ.T11.UPDATE.REQUEST
  
  name: MQ.T11.INQUIRY.REPLY
  JNDI name: jms/MQ.T11.UPDATE.REQUEST
  </code></pre>
  
  <p>DemoMain.java</p>
  
  <p>In main method:</p>
  
  <pre><code>ApplicationContext ctx = new ClassPathXmlApplicationContext("app-context.xml");
      // get bean from context
      JmsMessageSender jmsMessageSender = (JmsMessageSender)ctx.getBean("jmsMessageSender");
      // send to default destination 
           jmsMessageSender.send();
  </code></pre>
  
  <p>JMSMessageSender.java</p>
  
  <pre><code>package name: com.java.geek
  
   @Autowired
    private JmsTemplate jmsTemplate;
  
  
    /**
     * send text to default destination
     * @param text
     */
    @Cacheable("message")
    public void send() {
        System.out.println("in send");
          jmsTemplate.send(new MessageCreator() {
          @Override
          public Message createMessage(Session session)throws JMSException {
  
              System.out.println("in create message");
          Message message = (Message) session.createTextMessage("Hello JMS");
          return message;
          }
          });
  
      }
  
    public JmsTemplate getJmsTemplate()
    {
        return jmsTemplate;
    }
  
    public void setJmsTemplate(JmsTemplate jmsTemplate)
    {
        this.jmsTemplate = jmsTemplate;
    }
  </code></pre>
  
  <p>app-context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
  
    &lt;context:component-scan base-package="com.java.geek" /&gt;
  &lt;bean id="amqConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory"&gt;
      &lt;property name="hostName"&gt;
          &lt;value&gt;http://localhost:9043&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="port"&gt;
          &lt;value&gt;1415&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="queueManager"&gt;
          &lt;value&gt;MQDemo&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="transportType"&gt;
          &lt;value&gt;1&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
    &lt;!-- Pooled Spring connection factory --&gt;
    &lt;bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true"&gt; 
          &lt;property name="MQDemo" value="java:comp/env/jms/MQDemo" /&gt; 
           &lt;property name="lookupOnStartup" value="false"/&gt;
             &lt;property name="cache" value="true" /&gt;
             &lt;property name="proxyInterface"  value="javax.jms.QueueConnectionFactory"/&gt;
          &lt;constructor-arg ref="amqConnectionFactory" /&gt;
      &lt;/bean&gt;
  
  
    &lt;!-- JmsTemplate Definition --&gt;
    &lt;bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"&gt; 
          &lt;property name="connectionFactory"&gt;&lt;ref bean="amqConnectionFactory" /&gt;  &lt;/property&gt; 
          &lt;property name="pubSubDomain"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt; 
          &lt;!-- &lt;property name="defaultDestination"&gt;&lt;ref bean="senderQueue" /&gt;&lt;/property&gt;  --&gt;
      &lt;/bean&gt;  
  
      &lt;!-- ======================================================= --&gt;
    &lt;!-- JMS Send, define default destination and JmsTemplate    --&gt;
    &lt;!-- ======================================================= --&gt;
  
    &lt;!-- Default Destination Queue Definition --&gt;
    &lt;bean id="senderQueue" class="com.ibm.mq.jms.MQQueue"&gt; 
          &lt;constructor-arg value="MQ.T11.UPDATE.REQUEST"/&gt; 
      &lt;/bean&gt; 
      &lt;bean id="jmsMessageSender" class="com.java.geek.JmsMessageSender"&gt; 
          &lt;property name="jmsTemplate"&gt;&lt;ref bean="JmsTemplate"/&gt;&lt;/property&gt;     
      &lt;/bean&gt; 
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>I am getting an error, </p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
      at java.util.TimSort.mergeLo(TimSort.java:758)
      at java.util.TimSort.mergeAt(TimSort.java:494)
      at java.util.TimSort.mergeCollapse(TimSort.java:421)
      at java.util.TimSort.sort(TimSort.java:225)
      at java.util.TimSort.sort(TimSort.java:184)
      at java.util.Arrays.sort(Arrays.java:670)
      at com.ibm.mq.constants.MQConstants.getFields(MQConstants.java:277)
      at com.ibm.mq.constants.MQConstants.lookup(MQConstants.java:204)
      at com.ibm.mq.constants.MQConstants.lookup(MQConstants.java:264)
      at com.ibm.mq.constants.MQConstants.lookup(MQConstants.java:254)
      at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1862)
      at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1144)
      at com.ibm.msg.client.wmq.internal.WMQConnection.&lt;init&gt;(WMQConnection.java:337)
      at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:6772)
      at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:6151)
      at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:280)
      at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6138)
      at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:115)
      at com.ibm.mq.jms.MQQueueConnectionFactory.createConnection(MQQueueConnectionFactory.java:198)
      at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:185)
      at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:481)
      at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:566)
      at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:557)
      at com.java.geek.JmsMessageSender.send(JmsMessageSender.java:34)
      at com.java.geek.DemoMain.main(DemoMain.java:20)
  </code></pre>
  
  <p>which is coming at line </p>
  
  <pre><code>jmsTemplate.send(new MessageCreator() {
  </code></pre>
  
  <p>I am unable to connect to Websphere MQ. Kindly suggest where is a mistake in the code.</p>