-
Notifications
You must be signed in to change notification settings - Fork 39
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
feat: introduce java.time
methods
#1729
Merged
+44
−18
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e61c325
feat: introduce `java.time` methods
diegomarquezp b521713
feat: introduce `java.time` methods
diegomarquezp 37e767b
Merge branch 'introduce-java-time' of https://github.com/googleapis/j…
diegomarquezp d1feef2
use add-opens to allow serialization of java.time.Duration
diegomarquezp 5a5abd4
use add-opens in surefire only when running in jdk9+
diegomarquezp 2b09a03
Revert "use add-opens in surefire only when running in jdk9+"
diegomarquezp 46b9172
Revert "use add-opens to allow serialization of java.time.Duration"
diegomarquezp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qq, why is this DurationSerializer added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, the Gson serializer will try to access private methods/fields of Duration (and Instant - see the already-existing seralizer above). This seralizer relies on
toString()
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not following this part. Why does it try to access these methods + fields from Duration? Also, why is this an issue now and not previously?
Is this related to an error message/ stacktrace from a test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's meant to create a JSON string by accessing all its fields (i.e.
{"seconds":123,"nanos":123}
I'm trying to figure this out. The JDK version has both fields as private. So does the backport. Both also implement the same interfaces (
Serializable
,Comparable
,TemporalAmount
.The failing call happens in GSON when it tries to make the fields accessible - see below.
I'm not sure what this means:
java.base does not "opens java.time"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it has something to do with modules since this behaves perfectly fine if I run the test on java 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok gotcha. Thanks for take a look into this.
Can you see if doing
--add-opens java.base/java.time=ALL-UNNAMED
would work? Something similar to https://github.com/googleapis/java-datastore/blob/8244ad258a90e5bbc7e7d8ec384555b2be84ab8f/pom.xml#L251. If this does work, I think that could be an option to consider.Also, can you add a link for that to the PR Description as an explanation for why we are adding this.
The rest LGTM and I think we just need Cindy to review as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, add-opens works but the implementation was slightly different:
--add-opens
flag and is packed inside the jar as MANIFEST.mfThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I oversaw this brings trouble in units(8). Looking into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we are having a limitation. The following code activates the
--add-opens
flag in tests when the jdk version is >= 9:java-logging/pom.xml
Lines 305 to 317 in 5a5abd4
However, when running the CIs, we specify the runtime via the
-Djvm=...
option (absolute path to runtime), which varies among environments - seejava-logging/.github/workflows/ci.yaml
Lines 46 to 58 in 5a5abd4
and
java-logging/.kokoro/build.sh
Lines 49 to 53 in 5a5abd4
IIUC we would need a regex matcher for the
<activation>
entry to only include "paths not containing '1.8'".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll be reverting this maven config in the meantime