Skip to content

Calling avoidProxy with illegal URL throws NullPointerException #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scr opened this issue May 21, 2014 · 3 comments
Closed

Calling avoidProxy with illegal URL throws NullPointerException #560

scr opened this issue May 21, 2014 · 3 comments

Comments

@scr
Copy link

scr commented May 21, 2014

Below is a patch to ProxyUtilsTest.java that shows a reduction of the issue.

Running TestSuite
Tests run: 94, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 13.271 sec <<< FAILURE! - in TestSuite
testBasics(org.asynchttpclient.util.ProxyUtilsTest)  Time elapsed: 0.013 sec  <<< FAILURE!
java.lang.NullPointerException: null
    at org.asynchttpclient.util.ProxyUtils.avoidProxy(ProxyUtils.java:116)
    at org.asynchttpclient.util.ProxyUtils.avoidProxy(ProxyUtils.java:101)
    at org.asynchttpclient.util.ProxyUtilsTest.testBasics(ProxyUtilsTest.java:52)


Results :

Failed tests: 
  ProxyUtilsTest.testBasics:52 » NullPointer

---
diff --git a/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java b/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java
index fdcb888..19db97c 100644
--- a/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java
+++ b/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java
@@ -44,5 +44,11 @@ public class ProxyUtilsTest {
         proxyServer = new ProxyServer("foo", 1234);
         proxyServer.addNonProxyHost("*.somewhere.org");
         assertFalse(ProxyUtils.avoidProxy(proxyServer, req));
+
+        // shouldn't crash
+        req = new RequestBuilder("GET").setUrl("http://badhost/foo").build();
+        proxyServer = new ProxyServer("foo", 1234);
+        proxyServer.addNonProxyHost("*.somewhere.org");
+        assertFalse(ProxyUtils.avoidProxy(proxyServer, req));
     }
 }
scr pushed a commit to scr/async-http-client that referenced this issue May 21, 2014
@scr
Copy link
Author

scr commented May 22, 2014

Another test against AsyncHttpProviderUtils.createUri that should fail early if this would fail later.

diff --git a/api/src/test/java/org/asynchttpclient/util/AsyncHttpProviderUtilsTest.java b/api/src/test/java/org/asynchttpclient/util/AsyncHttpProviderUtilsTest.java
index 06ab8fb..669003c 100644
--- a/api/src/test/java/org/asynchttpclient/util/AsyncHttpProviderUtilsTest.java
+++ b/api/src/test/java/org/asynchttpclient/util/AsyncHttpProviderUtilsTest.java
@@ -13,6 +13,7 @@
 package org.asynchttpclient.util;

 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;

 import org.testng.annotations.Test;

@@ -44,4 +45,14 @@ public class AsyncHttpProviderUtilsTest {
         URI uri = AsyncHttpProviderUtils.getRedirectUri(URI.create("http://www.ebay.de/"), url);
         assertEquals(uri.toString(), "http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505");
     }
+    
+    @Test(groups = "fast")
+    public void createUriFailsWithBadHost() throws Exception {
+        try {
+            final String BAD_HOST_URL = "http:///";
+            URI uri = AsyncHttpProviderUtils.createUri(BAD_HOST_URL);
+            fail("Expected IllegalArgumentException for url: " + BAD_HOST_URL);
+        } catch (IllegalArgumentException ex) {
+        }
+    }
 }

scr pushed a commit to scr/async-http-client that referenced this issue May 22, 2014
@slandelle
Copy link
Contributor

@scr I have the feeling that you're trying to fix something downstream instead of right on the spot. How did you got this in the first place? Did you try to build a request and set an invalid url? Or did this happen during a redirect chain where AHC built the request automatically?

@slandelle
Copy link
Contributor

It's perfectly fine to have avoidProxy throw a NullPointerException when being passed a null hostname, that's exactly what NPE is about (although the message could be more explicit).

I'll open another issue regarding passing an url without a hostname to RequestBuilder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants