Author: bago
Date: Thu Apr 27 15:54:22 2006
New Revision: 397667

URL: http://svn.apache.org/viewcvs?rev=397667&view=rev
Log:
Fix for NPE in remotedelivery using gateway option and having no recipients in 
the message (JAMES-476)
Bug report and patch provided by Bernd Foremann

Modified:
    
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java

Modified: 
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java?rev=397667&r1=397666&r2=397667&view=diff
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
 Thu Apr 27 15:54:22 2006
@@ -1293,43 +1293,49 @@
                  * situation where the next gateway didn't have any
                  * valid addresses.
                  */
-                if ((addresses == null || !addresses.hasNext()) && 
gateways.hasNext()) do {
-                    String server = (String) gateways.next();
-                    String port = "25";
-
-                    int idx = server.indexOf(':'); 
-                    if ( idx > 0) { 
-                        port = server.substring(idx+1); 
-                        server = server.substring(0,idx);
-                    }
-
-                    final String nextGateway = server;
-                    final String nextGatewayPort = port;
-                    try {
-                        final InetAddress[] ips = 
org.apache.james.dnsserver.DNSServer.getAllByName(nextGateway);
-                        addresses = new Iterator() {
-                            private InetAddress[] ipAddresses = ips;
-                            int i = 0;
-
-                            public boolean hasNext() {
-                                return i < ipAddresses.length;
-                            }
-
-                            public Object next() {
-                                return new 
org.apache.mailet.HostAddress(nextGateway, "smtp://" + 
(ipAddresses[i++]).getHostAddress() + ":" + nextGatewayPort);
-                            }
-
-                            public void remove() {
-                                throw new UnsupportedOperationException 
("remove not supported by this iterator");
-                            }
-                        };
-                    }
-                    catch (java.net.UnknownHostException uhe) {
-                        log("Unknown gateway host: " + 
uhe.getMessage().trim());
-                        log("This could be a DNS server error or configuration 
error.");
-                    }
-                } while (!addresses.hasNext() && gateways.hasNext());
+                if (!hasNextAddress() && gateways.hasNext()) {
+                    do {
+                        String server = (String) gateways.next();
+                        String port = "25";
+
+                        int idx = server.indexOf(':');
+                        if ( idx > 0) {
+                            port = server.substring(idx+1);
+                            server = server.substring(0,idx);
+                        }
+
+                        final String nextGateway = server;
+                        final String nextGatewayPort = port;
+                        try {
+                            final InetAddress[] ips = 
org.apache.james.dnsserver.DNSServer.getAllByName(nextGateway);
+                            addresses = new Iterator() {
+                                private InetAddress[] ipAddresses = ips;
+                                int i = 0;
+
+                                public boolean hasNext() {
+                                    return i < ipAddresses.length;
+                                }
+
+                                public Object next() {
+                                    return new 
org.apache.mailet.HostAddress(nextGateway, "smtp://" + 
(ipAddresses[i++]).getHostAddress() + ":" + nextGatewayPort);
+                                }
+
+                                public void remove() {
+                                    throw new UnsupportedOperationException 
("remove not supported by this iterator");
+                                }
+                            };
+                        }
+                        catch (java.net.UnknownHostException uhe) {
+                            log("Unknown gateway host: " + 
uhe.getMessage().trim());
+                            log("This could be a DNS server error or 
configuration error.");
+                        }
+                    } while (!hasNextAddress() && gateways.hasNext());
+                } 
 
+                return hasNextAddress();
+            }
+
+            private boolean hasNextAddress() {
                 return addresses != null && addresses.hasNext();
             }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to