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

NPE if the server doesn't provide any HTTP content for an error #2532

Closed
chanseokoh opened this issue Jun 18, 2020 · 0 comments · Fixed by #2542
Closed

NPE if the server doesn't provide any HTTP content for an error #2532

chanseokoh opened this issue Jun 18, 2020 · 0 comments · Fixed by #2542
Assignees
Milestone

Comments

@chanseokoh
Copy link
Member

chanseokoh commented Jun 18, 2020

A user reported an NPE on the Gitter channel.

Caused by: java.lang.NullPointerException
	at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:889)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3005)
	at com.google.cloud.tools.jib.json.JsonTemplateMapper.readJson(JsonTemplateMapper.java:118)
	at com.google.cloud.tools.jib.json.JsonTemplateMapper.readJson (JsonTemplateMapper.java:118)
	at com.google.cloud.tools.jib.registry.RegistryEndpointCaller.newRegistryErrorException (RegistryEndpointCaller.java:194)

The NPE is when there was an error communicating with the server. Jib tries to parse the content of the error message (supposed to be a JSON) from the server.

      ErrorResponseTemplate errorResponse =
          JsonTemplateMapper.readJson(responseException.getContent(), ErrorResponseTemplate.class);

I noticed that if we pass a null string, JsonTemplateMapper.readJson() throws NPE with the same stacktrace.

JsonTemplateMapper.readJson((String) null, ErrorResponseTemplate.class);

Turns out responseException.getContent() can return null if there was no content from the server. The reason I think NullAway couldn't catch this is that the return value of getContet() basically comes from a method in the Google HTTP Client library.

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

Successfully merging a pull request may close this issue.

2 participants