Aws-sdk-java: java.lang.NoSuchMethodError: com.amazonaws.util.StringUtils.lowerCase

Created on 10 Mar 2016  路  10Comments  路  Source: aws/aws-sdk-java

When using version 1.10.59 to set up some things before creating a S3 bucket, we get a NoSuchMethodError complaining about a method in an SDK class not existing. Has this jar been built correctly?

java.lang.NoSuchMethodError: com.amazonaws.util.StringUtils.lowerCase(Ljava/lang/String;)Ljava/lang/String;
at com.amazonaws.services.s3.internal.RestUtils.makeS3CanonicalString(RestUtils.java:104)
at com.amazonaws.services.s3.internal.S3Signer.sign(S3Signer.java:169)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:821)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:597)
at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:363)
at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:329)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:308)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3674)
at com.amazonaws.services.s3.AmazonS3Client.headBucket(AmazonS3Client.java:1102)
at com.amazonaws.services.s3.AmazonS3Client.doesBucketExist(AmazonS3Client.java:1060)

Most helpful comment

@sunilkumarbm It looks like you have multiple versions of the SDK on your classpath somehow. You can try printing the location of where classes are being loaded to track this down.

System.out.println(StringUtils.getClass().getProtectionDomain().getCodeSource());
System.out.println(AwsProfileNameLoader.getClass().getProtectionDomain().getCodeSource());

All 10 comments

@kjc1 I know this has been awhile, but any clue as to how you resolved this problem?

What version of the SDK are you using?

any luck with this?

I'm using v 1.11.187
tries v 1.11.186 and 1.11.163.. everywhere, I'm getting the same issue
My error goes like this

Exception in thread "main" java.lang.NoSuchMethodError: com.amazonaws.util.StringUtils.trim(Ljava/lang/String;)Ljava/lang/String;
        at com.amazonaws.auth.profile.internal.AwsProfileNameLoader.getEnvProfileName(AwsProfileNameLoader.java:72)
        at com.amazonaws.auth.profile.internal.AwsProfileNameLoader.loadProfileName(AwsProfileNameLoader.java:54)
        at com.amazonaws.regions.AwsProfileRegionProvider.<init>(AwsProfileRegionProvider.java:40)
        at com.amazonaws.regions.DefaultAwsRegionProviderChain.<init>(DefaultAwsRegionProviderChain.java:23)
        at com.amazonaws.client.builder.AwsClientBuilder.<clinit>(AwsClientBuilder.java:58)

@sunilkumarbm It looks like you have multiple versions of the SDK on your classpath somehow. You can try printing the location of where classes are being loaded to track this down.

System.out.println(StringUtils.getClass().getProtectionDomain().getCodeSource());
System.out.println(AwsProfileNameLoader.getClass().getProtectionDomain().getCodeSource());

@shorea : Thanks for pointing me to the issue.
you are absolutely right. I'm getting the following when I add those 2 lines:

17/09/01 18:00:35 INFO S3Reader: (file:/dir/share/hadoop/tools/lib/aws-java-sdk-1.7.4.jar <no signer certificates>)
17/09/01 18:00:35 INFO S3Reader: (file:/dir/lib/aws-java-sdk-core-1.11.187.jar <no signer certificates>)

For my app, I need to load the second jar. But unfortunately, I cannot get rid of the first one as it is being used by hadoop for configuration management.

Is there any way I can ignore the second jar load the first jar?
I'm running the app in spark context.

@sunilkumarbm I have the exact same issue and i don't know what to do. Another dependency requires aws-java-sdk-1.7.4.jar, but our newest code requires aws-java-sdk-core-1.11.187.jar. And, AwsProfileNameLoader.getEnvProfileName() in 1.11.187 is trying to use StringUtils.trim() from aws-java-sdk-1.7.4.jar. Very strange. How can i tell a dependency to use the code in its own version? I'm using gradle.

@sunilkumarbm @jaguth Any luck on this issue? I am also facing the same problem and I'm not able to fix this issue.

Similar issue here. I tried what @sunilkumarbm suggested and the two printed paths are the same.
In my case, though, everything works fine on my local machine, but it produces that error when trying to run the Java as an action inside an Hadoop coordinator.

Any hints?

I had the similar issue in scala, I was using aws-sdk for different aws services.

Seq( "org.apache.spark" %% "spark-core" % sparkVer, "org.apache.spark" %% "spark-sql" % sparkVer, "com.databricks" %% "spark-csv" % spcsv_ver, "org.apache.hadoop" % "hadoop-aws" % "2.7.3", "com.amazonaws" % "aws-java-sdk-s3" % "1.11.375", "com.amazonaws" % "aws-java-sdk-bom" % "1.11.375", "com.amazonaws" % "aws-java-sdk-dynamodb" % "1.11.420", //"com.amazonaws" % "aws-java-sdk" % "1.7.4", "com.fasterxml.jackson.core" % "jackson-annotations" % "2.7.0", "com.datastax.spark" %% "spark-cassandra-connector" % "2.0.0-RC1", "org.apache.spark" %% "spark-hive" % sparkVer

This is how my build.sbt looks like. I tried to use the same version for dynamodb as I have to s3 and bom but it resulted in the above-mentioned error. So I just changed the version and worked well. Initially I was using 1.11.375 for dynamo.

I had the similar issue,

removing the dependency aws-java-sdk from my pom.xml and letting only the aws-java-sdk-rds worked for me.

the two dependencies had different versions.

Was this page helpful?
0 / 5 - 0 ratings