OpenFeign / OpenFeign/feign

InaccessibleObjectException with CompletableFuture on JDK16

Open
#1,453 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback provided
Dominant language
Java
Stars
9.8k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
41

Description

Using a basic interface :

public interface SomeResourceClient {
    @RequestLine("GET /resources")
    CompletableFuture<SomeResource> all();
}

With a basic configuration :

@Configuration
public class FeignConfig {
    @Bean
    public SomeResourceClient zeltyRoomClient(Gson gson) {
        return AsyncFeign.builder()
                .client(new OkHttpClient())
                .encoder(new GsonEncoder(gson))
                .decoder(new GsonDecoder(gson))
                .target(SomeResourceClient.class, "https://api.example.org/2.4");
    }
}

I have an exception on runtime with JDK 16 :

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field volatile java.lang.Object java.util.concurrent.CompletableFuture.result accessible: module java.base does not "opens java.util.concurrent" to unnamed module @6895a785
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
	at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
	at com.google.gson.internal.reflect.UnsafeReflectionAccessor.makeAccessible(UnsafeReflectionAccessor.java:44)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:159)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
	at com.google.gson.Gson.getAdapter(Gson.java:458)
	at com.google.gson.Gson.fromJson(Gson.java:931)
	at com.google.gson.Gson.fromJson(Gson.java:897)
	at feign.gson.GsonDecoder.decode(GsonDecoder.java:50)
	at feign.AsyncResponseHandler.decode(AsyncResponseHandler.java:115)
	... 72 more

Everything works perfectly without the CompletableFuture.
Is async calls supported on JDK16 ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided AsyncFeign configuration on JDK 16 and follow the stack trace through feign.gson.GsonDecoder and feign.AsyncResponseHandler into Gson's CompletableFuture handling. Compare the async and non-async cases, then verify whether the async call works without InaccessibleObjectException; the result should include a regression test or a clearly documented compatibility outcome.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.