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 334834 898a985fd269aab39ba07cb56ce402ccacd52ee2
parent 334833 20fb337ac107d7a62fd0bff7ad4148c87cd1f9f6
child 334835 8f26c5435bb14e6da2f48a00738a38b290b78013
push id1146
push userCallek@gmail.com
push dateMon, 25 Jul 2016 16:35:44 +0000
treeherdermozilla-release@a55778f9cd5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt, lizzard
bugs1270529
milestone48.0a2
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;
 import java.net.URI;
 import java.net.URLConnection;
 import java.util.List;
@@ -90,23 +91,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);