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

2.x client with Java 8 runtime and Apache HttpClient 5 Transport fails with java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer #904

Closed
peerkar opened this issue Mar 26, 2024 · 0 comments · Fixed by #920
Assignees
Labels
bug Something isn't working

Comments

@peerkar
Copy link

peerkar commented Mar 26, 2024

What is the bug?

When running the 2.9.1 client with Java 8 runtime and Apache HttpClient 5 Transport, I get the following exception when writing to the cluster:

java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
	at org.opensearch.client.transport.httpclient5.internal.HttpEntityAsyncEntityProducer.produce(HttpEntityAsyncEntityProducer.java:143)
	at org.apache.hc.core5.http.nio.support.BasicRequestProducer.produce(BasicRequestProducer.java:104)
	at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient$2.produce(InternalAbstractHttpAsyncClient.java:260)
	at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produce(HttpAsyncMainClientExec.java:163)
	at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.commitRequest(ClientHttp1StreamHandler.java:171)
	at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.lambda$produceOutput$0(ClientHttp1StreamHandler.java:183)
	at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produceRequest(HttpAsyncMainClientExec.java:150)
	at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.produceOutput(ClientHttp1StreamHandler.java:183)
	at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.execute(ClientHttp1StreamDuplexer.java:326)
	at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.processCommands(AbstractHttp1StreamDuplexer.java:239)
	at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onOutput(AbstractHttp1StreamDuplexer.java:386)
	at org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.outputReady(AbstractHttp1IOEventHandler.java:73)
	at org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.outputReady(ClientHttp1IOEventHandler.java:41)
	at org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:152)
	at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
	at org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)
	at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)
	at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:86)
	at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
	at java.lang.Thread.run(Thread.java:750)

Steps to reproduce

  1. Setup the OpenSearch server without security as described here

  2. Run the following test program:

package com.example;

import org.apache.hc.core5.http.HttpHost;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.opensearch.indices.CreateIndexRequest;
import org.opensearch.client.opensearch.indices.OpenSearchIndicesClient;
import org.opensearch.client.transport.OpenSearchTransport;
import org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder;

public class ExampleClient {

	public static void main(String[] args)   {

	    final ApacheHttpClient5TransportBuilder builder = ApacheHttpClient5TransportBuilder.builder(
	    		new HttpHost("http", "localhost", 9200));

	    OpenSearchTransport openSearchTransport = builder.build();
	    
	    OpenSearchClient openSearchClient = new OpenSearchClient(openSearchTransport);

	    OpenSearchIndicesClient openSearchIndicesClient = openSearchClient.indices();
	  
		try {
			openSearchIndicesClient.create(
				CreateIndexRequest.of(
					createIndexRequest->createIndexRequest.index("test_index")));
		} catch (Exception exception) {
			exception.printStackTrace();
		}
	}
}

Expected Results:
Index is created. No exceptions.

Actual Results:
An exception is thrown

Test environment

  • OpenSearch server 2.12.0
  • OpenSearch Java client 2.9.1 referenced as
// https://mvnrepository.com/artifact/org.opensearch.client/opensearch-java
implementation group: 'org.opensearch.client', name: 'opensearch-java', version: '2.9.1'

Possible Cause

Seems to be the same as described here

Changing this line

to

((Buffer) byteBuffer).flip();

and recompiling with JDK 11 seemed to fix the issue to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants