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

fixed unmarshaling van LocalDateTime error in the DDIExporterTest.java #8517

Merged
merged 4 commits into from
Mar 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package edu.harvard.iq.dataverse.export;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import edu.harvard.iq.dataverse.ControlledVocabularyValue;
import edu.harvard.iq.dataverse.DatasetFieldType;
import edu.harvard.iq.dataverse.DatasetFieldType.FieldType;
Expand All @@ -17,10 +21,15 @@
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -42,7 +51,10 @@ public class DDIExporterTest {
private static final SettingsServiceBean settingsService = Mockito.mock(SettingsServiceBean.class);
private static final LicenseServiceBean licenseService = Mockito.mock(LicenseServiceBean.class);
private static final MockDatasetFieldSvc datasetFieldTypeSvc = new MockDatasetFieldSvc();
private static final Gson gson = new Gson();
private static final Gson gson = new GsonBuilder().registerTypeAdapter(LocalDate.class, (JsonDeserializer<LocalDateTime>) (JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) -> {
Instant instant = Instant.ofEpochMilli(json.getAsJsonPrimitive().getAsLong());
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
}).create();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this test on my laptop and it works fine. It seems like a lot of boilerplate code.

I noticed that the InaccessibleObjectException error was first reported by @poikilotherm in an issue about Java 17:

@ErykKul are you running something newer than Java 11? In that issue, @poikilotherm suggests at upgrading Gson might fix this and what is perhaps a related issued here:

I can't reproduce the problem on Java 11 and haven't tried on anything newer. We aren't actively working on that Java 17 issue above but this pull request seems like a step in the right direction. I'm wondering, however, can you please try upgrading Gson to see if that's also a suitable fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried upgrading gson to 2.9.0, but it did not solve the problem. Downgrading to jdk11 helped, the test passes and in stead of errors I am getting warnings (with both gson versions; 2.9.0 and 2.2.4):
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ErykKul I appreciate you checking if upgrading Gson helps. Like I said, the tests still run fine on my laptop with your original change. They also run fine in CI. It's a little more boilerplate but it's confined to one test. If this helps us get to Java 17, great. Thanks for the pull request!


/*
* Setup and teardown mocks for BrandingUtil for atomicity.
Expand Down