Skip to content

Add OptionalUtil to Java util - #2464

Merged
mdedetrich merged 1 commit into
apache:mainfrom
mdedetrich:add-option-util
Nov 9, 2025
Merged

Add OptionalUtil to Java util#2464
mdedetrich merged 1 commit into
apache:mainfrom
mdedetrich:add-option-util

Conversation

@mdedetrich

@mdedetrich mdedetrich commented Nov 9, 2025

Copy link
Copy Markdown
Contributor

When working on #2409 I needed to convert from Java OptionalInt to Scala Option[Int] and I realized that due to Java Optional being invariant and Scala's Int being a subclass of Java's Integer you need some boilerplate in order convert from one to the other.

This boilerplate already lives in pekko-http since pekko-http already has this issue (see https://github.com/apache/pekko-http/blob/4833a8e42f946682a72a72a0f3bee4c4d662b9a6/http-core/src/main/java/org/apache/pekko/http/impl/util/Util.java) so this PR moves that code from pekko-http to pekko (since this will be the first time we need to use this code in pekko core).

Once 2.0.0-M1 will be published then we can change pekko-http 2.0.0 to use this code.

@mdedetrich mdedetrich added this to the 2.0.0-M1 milestone Nov 9, 2025
@@ -0,0 +1,64 @@
/*

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that even though this is technically a new file, the code is copied from https://github.com/apache/pekko-http/blob/4833a8e42f946682a72a72a0f3bee4c4d662b9a6/http-core/src/main/java/org/apache/pekko/http/impl/util/Util.java so we still need to use the lightbend header

Comment thread actor/src/main/java/org/apache/pekko/util/OptionalUtil.java Outdated
Comment thread actor/src/main/java/org/apache/pekko/util/OptionalUtil.java

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems generally ok but a couple of regression tests would be useful

@mdedetrich

mdedetrich commented Nov 9, 2025

Copy link
Copy Markdown
Contributor Author

seems generally ok but a couple of regression tests would be useful

Regression tests would be pointless due to how trivial the code is and also its case of if it compiles then it works, its just that I have split this PR out of the main work I am doing as part of zstd. We know that this code works as it was directly copied from pekko-http and its working locally with my zstd work

To put it differently, once other code starts using this code we know it will work because of that other work being able to compile. If someone changes the code in this PR to create a regression, than that other code that are using these utils will no longer compile.

@mdedetrich
mdedetrich merged commit 6d59962 into apache:main Nov 9, 2025
8 of 10 checks passed
@mdedetrich
mdedetrich deleted the add-option-util branch November 9, 2025 11:54
@mdedetrich

Copy link
Copy Markdown
Contributor Author

Thanks for the review, I created apache/pekko-http#869 as a reminder so that we use these methods in pekko-http once it starts depending on pekko 2.0.0-M1 milestone

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

Successfully merging this pull request may close these issues.

3 participants