Bug 1270529 - lookupProxy(): Return null if port is -1. r=ahunt, a=lizzard
authorSebastian Kaspari <s.kaspari@gmail.com>
Mon, 09 May 2016 20:08:12 +0200
changeset 378812 d1d5be37e3d09d5aa25889c3138d97dd4e11a15e
parent 378811 55d9570b4520adff40c2362d2e027655f4271f7a
child 378813 ad37649f586081a3a77109727caf54723d56ee9a
push id21011
push usermak77@bonardo.net
push dateThu, 16 Jun 2016 13:40:45 +0000
reviewersahunt, lizzard
bugs1270529
milestone47.0
Bug 1270529 - lookupProxy(): Return null if port is -1. r=ahunt, a=lizzard We already return null if the host is empty and all callers seem to handle null values. MozReview-Commit-ID: 4utRbvf7To3
mobile/android/base/java/org/mozilla/gecko/util/ProxySelector.java
--- a/mobile/android/base/java/org/mozilla/gecko/util/ProxySelector.java
+++ b/mobile/android/base/java/org/mozilla/gecko/util/ProxySelector.java
@@ -13,16 +13,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 // This code is based on AOSP /libcore/luni/src/main/java/java/net/ProxySelectorImpl.java
 
 package org.mozilla.gecko.util;
 
+import android.support.annotation.Nullable;
 import android.text.TextUtils;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.Proxy;
 
 public class ProxySelector {
     public ProxySelector() {
@@ -74,23 +75,29 @@ public class ProxySelector {
 
         return Proxy.NO_PROXY;
     }
 
     /**
      * Returns the proxy identified by the {@code hostKey} system property, or
      * null.
      */
+    @Nullable
     private Proxy lookupProxy(String hostKey, String portKey, Proxy.Type type, int defaultPort) {
-        String host = System.getProperty(hostKey);
+        final String host = System.getProperty(hostKey);
         if (TextUtils.isEmpty(host)) {
             return null;
         }
 
-        int port = getSystemPropertyInt(portKey, defaultPort);
+        final int port = getSystemPropertyInt(portKey, defaultPort);
+        if (port == -1) {
+            // Port can be -1. See bug 1270529.
+            return null;
+        }
+
         return new Proxy(type, InetSocketAddress.createUnresolved(host, port));
     }
 
     private int getSystemPropertyInt(String key, int defaultValue) {
         String string = System.getProperty(key);
         if (string != null) {
             try {
                 return Integer.parseInt(string);