Skip to content
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

NullPointerException while getting non-existent proxy #8

Closed
dernasherbrezon opened this issue Mar 23, 2017 · 3 comments
Closed

NullPointerException while getting non-existent proxy #8

dernasherbrezon opened this issue Mar 23, 2017 · 3 comments

Comments

@dernasherbrezon
Copy link

Steps to reproduce:

  • execute the following code (proxy "test" should not exist):
        ToxiproxyClient client = new ToxiproxyClient(env.getProperty("toxiproxy.baseUrl"),
                Integer.parseInt(env.getProperty("toxiproxy.port")));
        Proxy oldProxy = client.getProxy("test");

In logs:

Caused by: java.lang.NullPointerException
	at eu.rekawek.toxiproxy.HttpClient.readResponse(HttpClient.java:109)
	at eu.rekawek.toxiproxy.HttpClient.get(HttpClient.java:67)
	at eu.rekawek.toxiproxy.HttpClient.get(HttpClient.java:62)

Expected:

  • client.getProxy() method should return null if proxy doesn't exist
@trekawek
Copy link
Owner

While the NPE is certainly a bug, I think that throwing IOException would be a better option than returning null. toxiproxy-java is meant to be a thin client, translating the HTTP API into a Java API. Therefore error responses (like 404) should be translated into some kind of error, like Java exception.

In bbc47f3 I tried to make the error handling more resilient (no more NPEs). I hope it's acceptable for you.

BTW - which version of the Toxiproxy Server do you use? It's a bit strange that you don't get the correct JSON as a response for the request.

@dernasherbrezon
Copy link
Author

Hi!

I'm using toxiproxy 2.1.0 and I've got 404. Which means proxy was not found rather than IO problems. Having IOException may be misleading...Maybe better create method getProxyOrNull? Null is pretty valid here. Nothing found, nothing returned.

trekawek added a commit that referenced this issue Mar 24, 2017
@trekawek
Copy link
Owner

I can agree to getProxyOrNull :)

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

No branches or pull requests

2 participants