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

Unable to use Segment with JDK 17 #396

Closed
nidhi-nair opened this issue Dec 21, 2022 · 2 comments
Closed

Unable to use Segment with JDK 17 #396

nidhi-nair opened this issue Dec 21, 2022 · 2 comments

Comments

@nidhi-nair
Copy link

When trying to work with Segment analytics after upgrading to Spring Boot 3.0 + JDK 17, we're receiving the following error whenever our application attempts to publish an event:

com.google.gson.JsonIOException: Failed making field 'java.time.Instant#seconds' accessible; either change its visibility or write a custom TypeAdapter for its declaring type
Caused by: com.google.gson.JsonIOException: Failed making field 'java.time.Instant#seconds' accessible; either change its visibility or write a custom TypeAdapter for its declaring type
	at com.google.gson.internal.reflect.ReflectionHelper.makeAccessible(ReflectionHelper.java:23)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:203)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:112)
	at com.google.gson.Gson.getAdapter(Gson.java:531)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:137)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:211)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:112)
	at com.google.gson.Gson.getAdapter(Gson.java:531)
	at com.google.gson.Gson.getAdapter(Gson.java:629)
	at com.google.gson.internal.bind.ObjectTypeAdapter.write(ObjectTypeAdapter.java:176)
	at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69)
	at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:207)
	at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:144)
	at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:157)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:287)
	at com.google.gson.Gson.toJson(Gson.java:786)
	at com.google.gson.Gson.toJson(Gson.java:756)
	at com.google.gson.Gson.toJson(Gson.java:711)
	at com.google.gson.Gson.toJson(Gson.java:691)
	at com.segment.analytics.internal.AnalyticsClient.messageSizeInBytes(AnalyticsClient.java:144)
	at com.segment.analytics.internal.AnalyticsClient.enqueue(AnalyticsClient.java:170)
	at com.segment.analytics.Analytics.enqueue(Analytics.java:75)

The Gson error itself seems to be in line with the JPMS changes introduced in project Jigsaw. As mentioned in this issue, the expectation is that the Gson object is provided with TypeAdapters that handle the logic for how the failing types need to be serialized/deserialized.

However, Segment's AnalyticsClient seems to have abstracted away the Gson object that is meant to handle serialization logic for events and we are unable to add Type Adapters to it. Is it possible to expose the creation of this Gson instance?

A workaround we're using in the meantime, that has also been suggested in the above issue, is to provide JVM with the following argument:

--add-opens java.base/java.time=ALL-UNNAMED
@edsonjab
Copy link
Contributor

Hi @nidhi-nair thank you for your report, we start looking into this.

@nidhi-nair
Copy link
Author

Hey @edsonjab! Could you please help me out with what the usage should now look like to support custom converters?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants