Correct the logic in MBeanFactory.removeConnector() to ensure that the correct Connector is removed when there are multiple Connectors using different addresses but the same port.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc8.0.x/trunk@1833020 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/java/org/apache/catalina/mbeans/MBeanFactory.java b/java/org/apache/catalina/mbeans/MBeanFactory.java
index 0ebca04..d8deca6 100644
--- a/java/org/apache/catalina/mbeans/MBeanFactory.java
+++ b/java/org/apache/catalina/mbeans/MBeanFactory.java
@@ -18,6 +18,7 @@
 package org.apache.catalina.mbeans;
 
 import java.io.File;
+import java.net.InetAddress;
 
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -729,29 +730,32 @@
         ObjectName oname = new ObjectName(name);
         Service service = getService(oname);
         String port = oname.getKeyProperty("port");
-        //String address = oname.getKeyProperty("address");
+        String address = ObjectName.unquote(oname.getKeyProperty("address"));
 
         Connector conns[] = service.findConnectors();
 
         for (int i = 0; i < conns.length; i++) {
-            String connAddress = String.valueOf(conns[i].getProperty("address"));
+            String connAddress = null;
+            Object objConnAddress = conns[i].getProperty("address");
+            if (objConnAddress != null) {
+                connAddress = ((InetAddress) objConnAddress).getHostAddress();
+            }
             String connPort = ""+conns[i].getPort();
 
-            // if (((address.equals("null")) &&
-            if ((connAddress==null) && port.equals(connPort)) {
-                service.removeConnector(conns[i]);
-                conns[i].destroy();
-                break;
-            }
-            // } else if (address.equals(connAddress))
-            if (port.equals(connPort)) {
-                // Remove this component from its parent component
+            if (address == null) {
+                // Don't combine this with outer if or we could get an NPE in
+                // 'else if' below
+                if (connAddress == null && port.equals(connPort)) {
+                    service.removeConnector(conns[i]);
+                    conns[i].destroy();
+                    break;
+                }
+            } else if (address.equals(connAddress) && port.equals(connPort)) {
                 service.removeConnector(conns[i]);
                 conns[i].destroy();
                 break;
             }
         }
-
     }
 
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 9f91b97..c44e037 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -123,6 +123,11 @@
         <code>trustedProxies</code> but no <code>internalProxies</code>. Based
         on a patch by zhanhb. (markt)
       </fix>
+      <fix>
+        Correct the logic in <code>MBeanFactory.removeConnector()</code> to
+        ensure that the correct Connector is removed when there are multiple
+        Connectors using different addresses but the same port. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">