question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NoSuchMethodError when running S3 Mock in Java 8

See original GitHub issue

Hi there,

I am building a service that uses SpringBoot version 2.3.3 and java 8 which uses S3 Mock with Junit5 tests.

The version of S3 Mock that I am using is 2.1.26 which seems to have been built with a version higher than Java 8 if I got this right, which is causing the following exception to be thrown for me while trying to do something like this:

this is what I am trying to do

PutObjectRequest request = PutObjectRequest.builder()
                .bucket("blah")
                .key("foo/ab/cd/foo.json")
                .build();
        createClient().putObject(request, RequestBody.fromBytes(Base64.getEncoder().encode(UUID.randomUUID().toString().getBytes())));

and this is what I am getting

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:920)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:520)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:584)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1651)
	at com.adobe.testing.s3mock.KmsValidationFilter.doFilterInternal(KmsValidationFilter.java:91)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1638)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1638)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:103)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1638)
	at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1638)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1638)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:567)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1377)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:507)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1292)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:501)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:135)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
	at com.adobe.testing.s3mock.util.AwsChunkDecodingInputStream.readUntil(AwsChunkDecodingInputStream.java:108)
	at com.adobe.testing.s3mock.util.AwsChunkDecodingInputStream.read(AwsChunkDecodingInputStream.java:74)
	at java.io.InputStream.read(InputStream.java:170)
	at java.io.InputStream.read(InputStream.java:101)
	at com.adobe.testing.s3mock.domain.FileStore.inputStreamToFile(FileStore.java:445)
	at com.adobe.testing.s3mock.domain.FileStore.putS3Object(FileStore.java:255)
	at com.adobe.testing.s3mock.FileStoreController.putObject(FileStoreController.java:517)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)

I believe this has to do with the fact that from Java 9 onward the java.nio.ByteBuffer.clear returns a java.nio.ByteBuffer as opposed to Buffer in Java 8.

Can someone please shed some light on this if this is a genuine issue or if I have got something incorrectly?

UPDATE:

Running file against the class that causing the above exception gives me the following, which contradicts my intial guess

com/adobe/testing/s3mock/util/AwsChunkDecodingInputStream.class: compiled Java class data, version 52.0 (Java 1.8)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
HackerTheMonkeycommented, Sep 10, 2020

thanks guys for the quick response, much appreciated 🙌 🙏

I’ve used the new release and works great.

cheers

1reaction
HackerTheMonkeycommented, Sep 8, 2020

Right, I found what the problem is.

The releases of the S3 Mock is compiled with Java 11, using the source and target compiler argument set to 1.8, these arguments have been deprecated in favour of --release as they seem to leak JDK9+ dependencies into a java8 source and target build.

I have checked out your code and built it from source using:

1- When built as-is with java8, I get the following outcome:

private byte[] readUntil(byte[]) throws java.io.IOException;
    descriptor: ([B)[B
    Code:
       0: aload_0
       1: getfield      #6                  // Field byteBuffer:Ljava/nio/ByteBuffer;
       4: invokevirtual #18                 // Method java/nio/ByteBuffer.clear:()Ljava/nio/Buffer;     

which is what one would expect

2- When building it as is with Java 11, I get the following which is exactly what I get when using the pre-built jar downloaded from maven central

private byte[] readUntil(byte[]) throws java.io.IOException;
    descriptor: ([B)[B
    Code:
       0: aload_0
       1: getfield      #6                  // Field byteBuffer:Ljava/nio/ByteBuffer;
       4: invokevirtual #18                 // Method java/nio/ByteBuffer.clear:()Ljava/nio/ByteBuffer;      

3- Now, to prove that the above is correct, I have changed the pom section in the following manner and rebuilt with java 11 but with passing the compiler argument for 8:

before

<plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
          <configuration>
            <source>${java.version}</source>
            <target>${java.version}</target>
            <encoding>${project.build.sourceEncoding}</encoding>
          </configuration>
 </plugin>

after

<plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
          <configuration>
            <release>8</release>
            <encoding>${project.build.sourceEncoding}</encoding>
          </configuration>
</plugin>

And voila, now I get the expected outcome:

private byte[] readUntil(byte[]) throws java.io.IOException;
    descriptor: ([B)[B
    Code:
       0: aload_0
       1: getfield      #6                  // Field byteBuffer:Ljava/nio/ByteBuffer;
       4: invokevirtual #18                 // Method java/nio/ByteBuffer.clear:()Ljava/nio/Buffer;       

Happy to submit a PR if you guys are OK with the above

cheers

EDIT: remove the part from the bytecode that’s irrelevant to the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

spring - mockito test gives me problems with java.lang ...
I am trying to run a test, however I get this problem...I am new to Java spring/maven dependencies and I have no idea...
Read more >
Working with Amazon S3 objects - AWS SDK for Java 2.x
How to list, upload, download or delete objects in an Amazon S3 bucket using the AWS SDK for Java 2.x.
Read more >
Comment Filtering and Sorting - Issue Tracker
What is this error? You appear to have guava-jdk5 on your project buildScript or buildSrc classpath. This is likely a transitive dependency of...
Read more >
Amazon S3 Client :: Quarkiverse Documentation - GitHub Pages
Configuration property Type Default boolean false string localstack AWS SDK client configurations Type Default
Read more >
s3objectinputstream to string
To convert an InputStream Object int to a String using this method. ... Java Ssl Https Certificate; Java NoSuchMethodError:com.amazonaws.services.s3.model.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found