try { connection.setClientID(generateLocalAddress()); addressAssigned = true; } catch (javax.jms.IllegalStateException e) {  addressAssigned = true; } catch(javax.jms.InvalidClientIDException ex) {  } while(!addressAssigned) { try {
while(!addressAssigned) { try {
    public void start() throws Exception     {        if (initCtxFactory != null && providerUrl != null) {            Hashtable env = new Hashtable();            env.put(Context.INITIAL_CONTEXT_FACTORY, initCtxFactory);            env.put(Context.PROVIDER_URL, providerUrl);            ctx = new InitialContext(env);        } else            ctx = new InitialContext();        connectionFactory = (javax.jms.TopicConnectionFactory)ctx.lookup(cfName);                if (connectionFactory == null)            throw new IllegalArgumentException(                    "Topic connection factory cannot be found in JNDI.");                topic = (javax.jms.Topic)ctx.lookup(topicName);                if (topic == null)            throw new IllegalArgumentException("Topic cannot be found in JNDI.");        connection = connectionFactory.createTopicConnection();        boolean addressAssigned = false;                // check if JMS connection contains client ID,         // if not, try to assign randomly generated one        /*while(!addressAssigned) {            if (connection.getClientID() != null)                addressAssigned = true;            else                try {                    connection.setClientID(generateLocalAddress());                    addressAssigned = true;                } catch(javax.jms.InvalidClientIDException ex) {                    // duplicate... ok, let's try again                                    }        }*/        // Patch below submitted by Greg Woolsey        // Check if JMS connection contains client ID, if not, try to assign randomly generated one        // setClientID() must be the first method called on a new connection, per the JMS spec.        // If the client ID is already set, this will throw IllegalStateException and keep the original value.        try        {            connection.setClientID(generateLocalAddress());            addressAssigned = true;        } catch (javax.jms.IllegalStateException e) {            // expected if connection already has a client ID.            addressAssigned = true;        } catch(javax.jms.InvalidClientIDException ex) {            // duplicate... ok, let's try again        }        while(!addressAssigned)        {            try            {                connection.setClientID(generateLocalAddress());                addressAssigned = true;            } catch(javax.jms.InvalidClientIDException                    ex) {                // duplicate... ok, let's try again            }        }        local_addr = new JMSAddress(connection.getClientID(), false);        mcast_addr = new JMSAddress(topicName, true);        session = connection.createTopicSession(false,            javax.jms.Session.AUTO_ACKNOWLEDGE);        publisher = session.createPublisher(topic);        publisher.setTimeToLive(timeToLive);                subscriber = session.createSubscriber(topic);        subscriber.setMessageListener(this);                connection.start();        passUp(new Event(Event.SET_LOCAL_ADDRESS, local_addr));    }