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

Getting java.lang.NullPointerException while testing sdk's /settlement/transactions API for connection not available scenario #49

Open
Suryakanta26 opened this issue Feb 2, 2024 · 0 comments

Comments

@Suryakanta26
Copy link

Suryakanta26 commented Feb 2, 2024

Hi Team,

While doing testing with this SDK for connection failure scenario by removing the internet connection, I am getting NullPointerException. The stacktrace is below

"localizedMessage":"Cannot invoke \"String.length()\" because \"s\" is null","message":"Cannot invoke \"String.length()\" because \"s\" is null","name":"java.lang.NullPointerException","extendedStackTrace":[{"class":"[java.io](http://java.io/).StringReader","method":"<init>","file":"StringReader.java","line":51,"exact":false,"location":"?","version":"?"},{"class":"com.google.gson.JsonParser","method":"parseString","file":"JsonParser.java","line":51,"exact":false,"location":"gson-2.10.1.jar","version":"?"},{"class":"com.google.gson.JsonParser","method":"parse","file":"JsonParser.java","line":115,"exact":false,"location":"gson-2.10.1.jar","version":"?"},{"class":"com.global.api.utils.JsonDoc","method":"parse","file":"JsonDoc.java","line":292,"exact":false,"location":"globalpayments-sdk-11.1.24.jar","version":"?"},{"class":"com.global.api.utils.JsonDoc","method":"parse","file":"JsonDoc.java","line":289,"exact":false,"location":"globalpayments-sdk-11.1.24.jar","version":"?"},{"class":"com.global.api.entities.gpApi.GpApiTokenResponse","method":"<init>","file":"GpApiTokenResponse.java","line":107,"exact":false,"location":"globalpayments-sdk-11.1.24.jar","version":"?"},{"class":"com.global.api.gateways.GpApiConnector","method":"getAccessToken","file":"GpApiConnector.java","line":190,"exact":false,"location":"globalpayments-sdk-11.1.24.jar","version":"?"},{"class":"com.global.api.gateways.GpApiConnector","method":"signIn","file":"GpApiConnector.java","line":124,"exact":false,"location":"globalpayments-sdk-11.1.24.jar","version":"?"},{"class":"com.global.api.gateways.GpApiConnector","method":"processReport","file":"GpApiConnector.java","line":300,"exact":false,"location":"globalpayments-sdk-11.1.24.jar","version":"?"},{"class":"com.global.api.builders.ReportBuilder","method":"execute","file":"ReportBuilder.java","line":56,"exact":false,"location":"globalpayments-sdk-11.1.24.jar","version":"?"}

Expected Result:
SDK should return ApiException e.g. GatewayException/ConnectionException

Possible Solution:
For a connection failure scenario, signin() method gets GatewayException with null response. But due to the missing else
clause, the library failed to form ApiException in the below method. Resulting above NullPointerException.

GpApiConnector.generateGpApiException()

`
private void generateGpApiException(String responseCode, String responseText) throws GatewayException { 
 if (!StringUtils.isNullOrEmpty(responseText)) { 
      JsonDoc parsedResponse = JsonDoc.parse(responseText); 
      if (parsedResponse.has("error_code")) { 
          String errorCode = parsedResponse.getString("error_code"); 
          String detailedErrorCode = parsedResponse.getString("detailed_error_code"); 
          String detailedErrorDescription = parsedResponse.getString("detailed_error_description"); 
          throw new GatewayException(String.format("Status Code: %s - %s", responseCode, detailedErrorDescription), errorCode, 
          detailedErrorCode); 
      }
  }// Missing else clause 
 }
`

Requesting library maintainers to fix this.

Thanks.

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

1 participant