Author: norman
Date: Wed Jun 15 13:27:17 2011
New Revision: 1136031
URL: http://svn.apache.org/viewvc?rev=1136031&view=rev
Log:
Make sure MXHostAddressIterator does not throw a NPE when processing an invalid
MX-Record. See JAMES-1271
Modified:
james/server/trunk/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java
Modified:
james/server/trunk/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java?rev=1136031&r1=1136030&r2=1136031&view=diff
==============================================================================
---
james/server/trunk/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
(original)
+++
james/server/trunk/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
Wed Jun 15 13:27:17 2011
@@ -88,6 +88,9 @@ public class MXHostAddressIterator imple
} else {
addrs = dns.getAllByName(hostname);
}
+ for (int i = 0; i < addrs.length; i++) {
+ hAddresses.add(new org.apache.mailet.HostAddress(hostname,
"smtp://" + addrs[i].getHostAddress() + ":" + port));
+ }
} catch (UnknownHostException uhe) {
// this should never happen, since we just got
// this host from mxHosts, which should have
@@ -95,9 +98,7 @@ public class MXHostAddressIterator imple
StringBuffer logBuffer = new
StringBuffer(128).append("Couldn't resolve IP address for discovered host
").append(hostname).append(".");
logger.error(logBuffer.toString());
}
- for (int i = 0; i < addrs.length; i++) {
- hAddresses.add(new org.apache.mailet.HostAddress(hostname,
"smtp://" + addrs[i].getHostAddress() + ":" + port));
- }
+
}
addresses = hAddresses.iterator();
}
Modified:
james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java?rev=1136031&r1=1136030&r2=1136031&view=diff
==============================================================================
---
james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java
(original)
+++
james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java
Wed Jun 15 13:27:17 2011
@@ -79,4 +79,43 @@ public class MXHostAddressIteratorTest e
}
assertFalse(it.hasNext());
}
+
+
+ public void testIteratorWithInvalidMX() {
+ DNSService dns = new DNSService() {
+
+ public InetAddress getLocalHost() throws UnknownHostException {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getHostName(InetAddress addr) {
+ throw new UnsupportedOperationException();
+ }
+
+ public InetAddress getByName(String host) throws
UnknownHostException {
+ throw new UnknownHostException();
+ }
+
+ /**
+ * Every time this method is called it will return two InetAddress
instances
+ */
+ public InetAddress[] getAllByName(String host) throws
UnknownHostException {
+ throw new UnknownHostException();
+ }
+
+ public Collection<String> findTXTRecords(String hostname) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> findMXRecords(String hostname) throws
TemporaryResolutionException {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ // See JAMES-1271
+ MXHostAddressIterator it = new
MXHostAddressIterator(Arrays.asList("localhost").iterator(), dns, false,
LoggerFactory.getLogger(this.getClass()));
+ assertFalse(it.hasNext());
+
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]