I am trying to use the Digital Ocean java library and when trying to create a connection with:
CloseableHttpClient httpClient = HttpClients.createDefault();
client = new DigitalOceanClient("v2", token, httpClient);
The problem lies in the CloseableHttpClient httpClient object. The library uses httpcore version 4.4.1 and httpclient version 4.5. It gives me a java.lang.NoSuchFieldError.
Here's my log:
Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:955)
at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58)
at main.java.servers.DigitalOceanServer.setup(DigitalOceanServer.java:28)
I found little information and documentation on the NoSuchFieldError, so I'm assuming it has to do with the version of httpcore and/or httpclient that causes this error.
The field variable
INSTANCEhas been introduced in AllowAllHostnameVerifier.java since Apache httpclient version 4.4.If both new version of
SSLConnectionSocketFactoryand old version ofAllowAllHostnameVerifieris used, thenjava.lang.NoSuchFieldError: INSTANCEis thrown.One of the possible cause is two version of Apache httpclient jar are in your library directory.