Christopher Barham | 25 Jan 03:22

possible Bug report-BaseChannel multiple hosts inconsistency (from r2568 commit)

Hi,
I've just spent some time upgrading my jPos installation and found a
problem resulting from the multi-hosts changes made as part of
subversion r2568.  Basically, I use aChannel.setHost("host") followed by
aChannel.setPort(123456) and am getting NullPointerException deep in the
socket code.  Tracing this through, it seems there is now an
inconsistency in how the host/port setter is carried out depending on
whether you call setHost(String host, int port) or setHost(String host)
followed by setPort(int port) in BaseChannel.

In order to make myself clearer may I present the following jUnit 4 test
exposing the issue, (the test requires use of jUnit 4 from
http://www.junit.org and junit addons from
http://junit-addons.sourceforge.net to get at the private fields) :

Please can you advise as to whether this is intended behaviour?  If not,
may I suggest that BaseChannel be amended so that host and channel are
removed as fields, and the getter/setter will interact with the hosts
and ports arrays, using the first position only?

<CODE>
package org.jpos.iso;

import static org.junit.Assert.assertEquals;
import junit.framework.JUnit4TestAdapter;

import org.junit.Before;
import org.junit.Test;

public class BaseChannelSetterTest {
     private BaseChannel m_channel;
     private String m_testHost;
     private int m_testPort;

     public static junit.framework.Test suite() {
         return new JUnit4TestAdapter(BaseChannelSetterTest.class);
     }

     @Test
     public void setHostAndPort() throws Exception {
         m_channel.setHost(m_testHost, m_testPort);

         assertCorrectHostAndPort(m_channel, m_testHost, m_testPort);
     }

     @Test
     public void setHostAndPortSingular() throws Exception {
         m_channel.setHost(m_testHost);
         m_channel.setPort(m_testPort);

         assertCorrectHostAndPort(m_channel, m_testHost, m_testPort);
     }

     @Before
     public void setUp() {
         m_channel = new BaseChannel() {
         };
         m_testPort = 123456;
         m_testHost = "127.0.0.1";
     }

     private void assertCorrectHostAndPort(BaseChannel aChannel, String
expectedHost, int expectedPort)
             throws NoSuchFieldException {
         assertEquals("Wrong Host", expectedHost, aChannel.getHost());
         assertEquals("Wrong Port", expectedPort, aChannel.getPort());

         // TODO: desire a getter for the Array based host/ports var
         int[] ports =
(int[])junitx.util.PrivateAccessor.getField(aChannel, "ports");
         // TODO: ports[] and hosts[] vars have diff visibility in
BaseChannel ?
         String[] hosts =
(String[])junitx.util.PrivateAccessor.getField(aChannel, "hosts");

         // Ensure that both the host and Host[0] and port and port[0]
are set the same
         assertEquals("Single and Array port vars mismatch",
aChannel.getPort(), ports[0]);
         assertEquals("Single and Array hosts vars mismatch",
aChannel.getHost(), hosts[0]);
     }
}

</CODE>

Regards,
Chris

[Non-text portions of this message have been removed]

 

Gmane