feign icon indicating copy to clipboard operation
feign copied to clipboard

InaccessibleObjectException with CompletableFuture on JDK16

Open cpoissonnier opened this issue 3 years ago • 4 comments

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 ?

cpoissonnier avatar Jul 07 '21 14:07 cpoissonnier

Well, we wrote it targeting JDK11, seems JDK16 broke the API somehow.

But, are you sure GSON works with JDK16?

velo avatar Jul 07 '21 21:07 velo

Yes, it works, we were already using it :)

cpoissonnier avatar Jul 08 '21 06:07 cpoissonnier

That's really strange that a JDK related item needs to be set accessible. Feels odd and it's not Feign that's responsible here. Anyway, we'll do some testing and see.

kdavisk6 avatar Jul 19 '21 13:07 kdavisk6

Here is your answer, java.util.concurrent is not open by default: https://www.sebastianbuza.com/2021/02/03/jep-396-and-you-strong-encapsulation-of-the-jdk-internals-is-the-default-java-code-geeks/

Regardless, we'll still see if something related to what's in the CompleteableFuture

kdavisk6 avatar Jul 19 '21 13:07 kdavisk6