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 NULL Pointer exception while publishing text SMS using AWS SNS #2238

Closed
rajasvs opened this issue Jan 13, 2021 · 7 comments
Closed
Labels
closed-for-staleness guidance Question that needs advice or information.

Comments

@rajasvs
Copy link

rajasvs commented Jan 13, 2021

Current Behavior

While trying to publish text message, i'm getting the NULL pointer exception.

Pasting the Logs:
java.lang.NullPointerException: java.lang.NullPointerExceptionjava.lang.NullPointerException at software.amazon.awssdk.core.internal.handler.BaseClientHandler.finalizeSdkHttpFullRequest(BaseClientHandler.java:80) at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.doExecute(BaseSyncClientHandler.java:143) at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.lambda$execute$1(BaseSyncClientHandler.java:112) at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.measureApiCallSuccess(BaseSyncClientHandler.java:167) at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.execute(BaseSyncClientHandler.java:94) at software.amazon.awssdk.core.client.handler.SdkSyncClientHandler.execute(SdkSyncClientHandler.java:45) at software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.execute(AwsSyncClientHandler.java:55) at software.amazon.awssdk.services.sns.DefaultSnsClient.publish(DefaultSnsClient.java:2130) at com.webapp3.webapp3.Handler.pubTextSMS(Handler.java:340) at com.webapp3.webapp3.Handler.handleRequest(Handler.java:108) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source)

Steps to Reproduce (for bugs)

Pasting the code i used.
SnsClient snsClient = SnsClient.builder()
.region(software.amazon.awssdk.regions.Region.AP_SOUTH_1)
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.build();

PublishRequest request = PublishRequest.builder()
.message(message)
.phoneNumber(phoneNumber)
.build();

        PublishResponse result = snsClient.publish(request);

Observed the same issue even without providing ".credentialsProvider" and also "with US region"

Context

Your Environment

  • AWS Java SDK version used: aws-sdk-java-v2
  • JDK version used: corretta 11
  • Operating System and version: Lambda and Java application
@debora-ito debora-ito added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Jan 13, 2021
@debora-ito
Copy link
Member

@rajasvs what version of the SDK you are using specifically - e.g. version 2.15.64 is the latest.

Also, can you check for dependency version mismatches in your environment? If you're using maven you can run mvn dependency:tree.

@debora-ito debora-ito added closing-soon This issue will close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. and removed needs-triage This issue or PR still needs to be triaged. closing-soon This issue will close in 4 days unless further comments are made. labels Jan 14, 2021
@rajasvs
Copy link
Author

rajasvs commented Jan 14, 2021 via email

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jan 14, 2021
@debora-ito
Copy link
Member

The Java SDK 2.x dependencies seem to be ok, they are all in version 2.15.61.

I see you are also building the Java SDK 1.11.x modules as dependencies, is this expected? It is not an issue, you can use both versions side to side, it's just unusual to use both versions at the same time.

@debora-ito debora-ito added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jan 15, 2021
@rajasvs
Copy link
Author

rajasvs commented Jan 15, 2021

I have a little confusion here.
There is a set of packages under com:amazonaws: These packages currently have version 1.11.x
Examples;
com:amazonaws:aws-java-sdk-lambda
com:amazonaws:aws-java-sdk-sns

And, there is another set of packages under software:amazon:awssdk: These packages currently have version 2.15.x
Examples:
software:amazon:awssdk:lambda
software:amazon:awssdk:sns

My question is, which one should i use. And what is the difference between these two sets? I'm trying to develop a web service which tracks and sends notifications to end user. And, I intend to use Lambda, dynamoDB, SNS, API Gateway, etc. Kindly suggest.

One additional question: what is difference between software:amazon:awssdk/aws-sdk and software:amazon:awssdk/sdk-core?

Thanks
Raj

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jan 15, 2021
@debora-ito
Copy link
Member

Java SDK 2.x is a rewrite of version 1.11.x, and it has many features and improvements like non-blocking IO, automatic pagination and immutability - for more details you can read the 2.x release announcement or the Developer Guide.

For new projects we definitely recommend using version 2.x.

Here's an example of how your pom.xml should look like with lambda and sns as dependencies:

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>software.amazon.awssdk</groupId>
        <artifactId>bom</artifactId>
        <version>2.15.66</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>lambda</artifactId>
    </dependency>
    <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>sns</artifactId>
    </dependency>
    ....

I see you also use some of the aws/aws-lambda-java-libs libraries, so add them as well:

....
<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-lambda-java-core</artifactId>
  <version>1.2.1</version>
</dependency>
<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-lambda-java-events</artifactId>
  <version>3.7.0</version>
</dependency>
<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-lambda-java-log4j2</artifactId>
  <version>1.2.0</version>
</dependency>
....

Please let us know if you still see the NullPointerException after using only the SDK 2.15.x modules.

@debora-ito debora-ito added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jan 16, 2021
@rajasvs
Copy link
Author

rajasvs commented Jan 19, 2021

Hi Debora,

I have made the changes you have suggested and now the NULL pointer exception problem doesn't occur. THANKS for your Help in resolving this. I appreciate your timely responses.

Additional Note:
All SNS API calls i used succeeded, but i'm not able to send SMS message to a mobile number in india. I realize that there are limitation or specifications in using SMS service in india. So i tried to use route type as "promotional" and presumed that it uses International Long Distance Operator (ILDO) mode by default rather than local routes. Not sure what i'm missing here.

Please let me know if i have to raise a separate case for this. Thanks.

Regards
Raj

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jan 19, 2021
@debora-ito
Copy link
Member

Hi Raj, I don't have the knowledge to help out with sending SMS messages to recipients in India, apart from what is described in the SNS Developer Guide - SMS requirements for India.

This is a service specific question, I recommend you open a case with AWS Support or reach out to the developer community in StackOverflow - found this SO question, it might help: https://stackoverflow.com/questions/40840783/sending-sms-notification-for-indian-mobile-numbers-from-aws-sns.

@debora-ito debora-ito added the closing-soon This issue will close in 4 days unless further comments are made. label Jan 20, 2021
@github-actions github-actions bot added closed-for-staleness and removed closing-soon This issue will close in 4 days unless further comments are made. labels Jan 24, 2021
aws-sdk-java-automation added a commit that referenced this issue Nov 8, 2022
…3a313de11

Pull request: release <- staging/6965cb5b-fd0f-4b18-872f-a1c3a313de11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

2 participants