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

null pointer exception in networkResponse.statusCode #3628

Open
pradeepkumarreddyk opened this issue Aug 23, 2016 · 6 comments
Open

null pointer exception in networkResponse.statusCode #3628

pradeepkumarreddyk opened this issue Aug 23, 2016 · 6 comments

Comments

@pradeepkumarreddyk
Copy link

pradeepkumarreddyk commented Aug 23, 2016

The following is the swagger generated code for android:-

try {
        String localVarResponse = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
        if(localVarResponse != null){
           return (Lxlresponse) ApiInvoker.deserialize(localVarResponse, "", Lxlresponse.class);
        } else {
           return null;
        }
      } catch (ApiException ex) {
         throw ex;
      } catch (InterruptedException ex) {
         throw ex;
      } catch (ExecutionException ex) {

         if(ex.getCause() instanceof VolleyError) {

             throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());
         }
         throw ex;
      } catch (TimeoutException ex) {
         throw ex;
      }
  }

In the above code, at the following line i'm getting null pointer exception, when there is no response from server:-

throw new ApiException(((VolleyError) ex.getCause()).networkResponse.statusCode, ((VolleyError) ex.getCause()).getMessage());

@wing328
Copy link
Contributor

wing328 commented Aug 24, 2016

@pradeepkumarreddyk thanks for reporting the issue. The address it, we need to do a null check for networkResponse before accessing the statusCode. If networkResponse is null, we will pass the status code as 0.

May I know if you've cycle to contribute the enhancement/bug fix?

@wing328 wing328 added this to the v2.2.2 milestone Aug 24, 2016
@pradeepkumarreddyk
Copy link
Author

i did not understand. what is cycle to contribute the bug fix ?

@wing328
Copy link
Contributor

wing328 commented Oct 14, 2016

I mean do you have time to contribute the fix.

@pradeepkumarreddyk
Copy link
Author

pradeepkumarreddyk commented Oct 14, 2016

yes, i have time to contribute the fix.

what are the steps i should follow to contribute the fix.

First i need to clone the code, then modify the code to fix the bug, then create a pull request.
am i right ?

On Fri, Oct 14, 2016 at 7:55 AM, wing328 notifications@github.com wrote:

I mean do you have time to contribute the fix.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#3628 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATYHCldGFjLYs8wyrdFEhFF3iHj7XIaEks5qzughgaJpZM4JqjJe
.

@wing328
Copy link
Contributor

wing328 commented Oct 14, 2016

Yes, you're correct. The following file is a good starting point:

try {
String localVarResponse = apiInvoker.invokeAPI (basePath, path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, contentType, authNames);
if(localVarResponse != null){
return {{#returnType}}({{{returnType}}}) ApiInvoker.deserialize(localVarResponse, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
} else {
return {{#returnType}}null{{/returnType}};
}
} catch (ApiException ex) {
throw ex;
} catch (InterruptedException ex) {
throw ex;
} catch (ExecutionException ex) {
if(ex.getCause() instanceof VolleyError) {
VolleyError volleyError = (VolleyError)ex.getCause();
if (volleyError.networkResponse != null) {
throw new ApiException(volleyError.networkResponse.statusCode, volleyError.getMessage());
}
}
throw ex;
} catch (TimeoutException ex) {
throw ex;
}
}

Let us know if you need any help.

@pradeepkumarreddyk
Copy link
Author

i have cloned the swagger-codegen code, then i have executed the following
command on top level directory to find out the list of files which need
modification.

grep -r volleyError.networkResponse *

Output of the above command is as follows :-

modules/swagger-codegen/src/main/resources/android/libraries/volley/api.mustache:
if (volleyError.networkResponse != null) {
modules/swagger-codegen/src/main/resources/android/libraries/volley/api.mustache:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/StoreApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/StoreApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/StoreApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/StoreApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/StoreApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/StoreApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/StoreApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/StoreApi.java:
throw new ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
throw new
ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
throw new
ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
throw new
ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
throw new
ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
throw new
ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
throw new
ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
throw new
ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
if (volleyError.networkResponse != null) {
samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/UserApi.java:
throw new
ApiException(volleyError.networkResponse.statusCode,
volleyError.getMessage());

=> i did not find even a single instance where null check is not done.
Everywhere null check is already done in the code.
What should i do ?

On Fri, Oct 14, 2016 at 2:44 PM, wing328 notifications@github.com wrote:

Yes, you're correct. The following file is a good starting point:

https://github.com/swagger-api/swagger-codegen/blob/
1dd9ee3/modules/swagger-
codegen/src/main/resources/android/libraries/volley/api.mustache#L112-L134


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#3628 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATYHCjDm3Cx6u8RQ83goMwwnkIXeYkt_ks5qz0gSgaJpZM4JqjJe
.

@wing328 wing328 modified the milestones: Future, v2.2.2 Feb 16, 2017
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