spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 356 forks source link

Regression in (Simple)ClientHttpRequestFactory concerning Nativehints #1636

Closed goafabric closed 2 years ago

goafabric commented 2 years ago

Description The Regression concerning Nativehints + (Simple)ClientHttpRequestFactory that was fixed multiple times, is again existent in 0.12. See #1370

Setting a ConnectionTimeout e.g. via RestTemplateBuilder: new RestTemplateBuilder().setConnectTimeout(Duration.ofMillis(timeout))

Symptom Crashes during Bootstrap: java.lang.IllegalStateException: Request factory class org.springframework.http.client.SimpleClientHttpRequestFactory does not have a suitable setConnectTimeout method

Mitigation As always we can mitigate this, by setting a manual Typehint: @TypeHint(types = org.springframework.http.client.SimpleClientHttpRequestFactory.class, access = {TypeAccess.DECLARED_CONSTRUCTORS, TypeAccess.PUBLIC_METHODS})

But it would be nice if this thing get's fixed once and for all. Really odd that is .. because #1370 seems to contain a merge request that sets the hints.

mhalbritter commented 2 years ago

Thanks for the report. I'll add a sample to that our CI will catch that in the future.

mhalbritter commented 2 years ago

Huh, this is indeed very strange. The hints are there, but they are not generated into the reflect-config.json.

When i add

@MethodHint(name = "setProxy", parameterTypes = Proxy.class)

this will show up in the JSON. Maybe the primitive type handling is broken, because int and boolean don't show up. Have to debug the JSON file generation.

mhalbritter commented 2 years ago

Running it with debug output reveals:

org.springframework.nativex.type.Type    : Unable to fully resolve method setConnectTimeout(int)
org.springframework.nativex.type.Type    : Unable to fully resolve method setReadTimeout(int)
org.springframework.nativex.type.Type    : Unable to fully resolve method setBufferRequestBody(boolean)

This is logged from org.springframework.nativex.type.Type#unpackMethodInfo, and it seems that it can't resolve primitive types.