Source:
<code>public static Destination lookupDestination(Context context, String destinationName, String destinationType) throws NamingException { if (null == destinationName) { return null; } try { return JMSUtils.lookup(context, Destination.class, destinationName); } catch (NameNotFoundException e) { try { Properties initialContextProperties = new Properties(); <START> if (null != context.getEnvironment()) { <END> if (null != context.getEnvironment().get(JMSConstants.NAMING_FACTORY_INITIAL)) { initialContextProperties.put(JMSConstants.NAMING_FACTORY_INITIAL, context.getEnvironment().get(JMSConstants.NAMING_FACTORY_INITIAL)); } if (null != context.getEnvironment().get(JMSConstants.CONNECTION_STRING)) { initialContextProperties.put(JMSConstants.CONNECTION_STRING, context.getEnvironment().get(JMSConstants.CONNECTION_STRING)); } if (null != context.getEnvironment().get(JMSConstants.PROVIDER_URL)) { initialContextProperties.put(JMSConstants.PROVIDER_URL, context.getEnvironment().get(JMSConstants.PROVIDER_URL)); } } if (JMSConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType)) { initialContextProperties.put(JMSConstants.TOPIC_PREFIX + destinationName, destinationName); } else if (JMSConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(destinationType) || JMSConstants.DESTINATION_TYPE_GENERIC.equalsIgnoreCase(destinationType)) { initialContextProperties.put(JMSConstants.QUEUE_PREFIX + destinationName, destinationName); } InitialContext initialContext = new InitialContext(initialContextProperties); try { return JMSUtils.lookup(initialContext, Destination.class, destinationName); } catch (NamingException e1) { return JMSUtils.lookup(context, Destination.class, (JMSConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType) ? "dynamicTopics/" : "dynamicQueues/") + destinationName); } } catch (NamingException ex) { log.warn("Cannot locate destination : " + destinationName); throw ex; } } catch (NamingException ex) { log.warn("Cannot locate destination : " + destinationName, ex); throw ex; } }</code><technical_language>null checks needed? Counter question done if null? If do wish continue exception thrown</technical_language>

Target:
public static Destination lookupDestination(Context context, String destinationName, String destinationType) throws NamingException { if (null == destinationName) { return null; } try { return JMSUtils.lookup(context, Destination.class, destinationName); } catch (NameNotFoundException e) { Properties initialContextProperties = new Properties(); initialContextProperties.put(JMSConstants.NAMING_FACTORY_INITIAL, context.getEnvironment().get(JMSConstants.NAMING_FACTORY_INITIAL)); initialContextProperties .put(JMSConstants.PROVIDER_URL, context.getEnvironment().get(JMSConstants.PROVIDER_URL)); if (null != context.getEnvironment().get(JMSConstants.CONNECTION_STRING)) { initialContextProperties.put(JMSConstants.CONNECTION_STRING, context.getEnvironment().get(JMSConstants.CONNECTION_STRING)); } if (JMSConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType)) { initialContextProperties.put(JMSConstants.TOPIC_PREFIX + destinationName, destinationName); } else if (JMSConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(destinationType) || JMSConstants.DESTINATION_TYPE_GENERIC.equalsIgnoreCase(destinationType)) { initialContextProperties.put(JMSConstants.QUEUE_PREFIX + destinationName, destinationName); } InitialContext initialContext = new InitialContext(initialContextProperties); try { return JMSUtils.lookup(initialContext, Destination.class, destinationName); } catch (NamingException e1) { return JMSUtils.lookup(context, Destination.class, (JMSConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType) ? "dynamicTopics/" : "dynamicQueues/") + destinationName); } } }