You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an ApiException is thrown and exception.printStackTrace() or just exception.getMessage() is called, then a NullPointerException is thrown due to this line in the getMessage() function implementation:
If this.getResponseHeaders() is null, then .toString() throws NPE.
Steps to reproduce?
When sending a notification fails:
apiClient.createNotificationAsync(
notification,
new ApiCallback<>() {
@Override
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
logger.info("Notification send failed with status code: "+ statusCode);
if(e != null) e.printStackTrace();
}
@Override public void onSuccess(CreateNotificationSuccessResponse result, int statusCode, Map<String, List<String>> responseHeaders) { System.out.println("Push notification sent: " + result.toJson()); } @Override public void onUploadProgress(long bytesWritten, long contentLength, boolean done) { } @Override public void onDownloadProgress(long bytesRead, long contentLength, boolean done) { } } );
What did you expect to happen?
exception.printStackTrace() or exception.getMessage() should not throw NPE.
Relevant log output
Exception in thread "OkHttp Dispatcher" java.lang.NullPointerException: Cannot invoke "java.util.Map.toString()" because the return value of "com.onesignal.client.ApiException.getResponseHeaders()" is null
at com.onesignal.client.ApiException.getMessage(ApiException.java:164)
at java.base/java.lang.Throwable.getLocalizedMessage(Throwable.java:397)
at java.base/java.lang.Throwable.toString(Throwable.java:496)
at java.base/java.lang.String.valueOf(String.java:4218)
at java.base/java.io.PrintStream.println(PrintStream.java:1047)
at java.base/java.lang.Throwable$WrappedPrintStream.println(Throwable.java:763)
at java.base/java.lang.Throwable.printStackTrace(Throwable.java:670)
at java.base/java.lang.Throwable.printStackTrace(Throwable.java:659)
at java.base/java.lang.Throwable.printStackTrace(Throwable.java:650)
at com.myapp.backend.notification.client.NotificationClient$2.onFailure(NotificationClient.java:97)
at com.onesignal.client.ApiClient$1.onResponse(ApiClient.java:1038)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
Hello there! Apologies that this issue has gone stale. We have made several improvements and enhancements since this the last activity here. If this is still any problems with this, please open a new issue so we can renew investigation. Thank you!
What happened?
When an
ApiException
is thrown andexception.printStackTrace()
or justexception.getMessage()
is called, then aNullPointerException
is thrown due to this line in the getMessage() function implementation:If
this.getResponseHeaders()
is null, then.toString()
throws NPE.Steps to reproduce?
What did you expect to happen?
exception.printStackTrace()
orexception.getMessage()
should not throw NPE.Relevant log output
Code of Conduct
The text was updated successfully, but these errors were encountered: