You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2025/09/14 07:32:22 UTC

[PR] feat: Add sneakyThrow for Java [pekko]

He-Pin opened a new pull request, #2218:
URL: https://github.com/apache/pekko/pull/2218

   Motivation:
   When lambda doesn't support throwing exceptions, but the method we want to use declares that it throws exceptions, we can use this method to support it, similar to lombok's @sneakyThrows.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat: Add sneakyThrow for Java [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #2218:
URL: https://github.com/apache/pekko/pull/2218#issuecomment-3314875348

   > > Don't find a good place to add
   > 
   > Okay I can do it, don't forget to backport this
   
   Can we make the backport be in 1.3.0? I haven't yet create a 1.3.x branch and it makes life easier for me to wait until after the 1.2.1 release to do this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat: Add sneakyThrow for Java [pekko]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2218:
URL: https://github.com/apache/pekko/pull/2218#discussion_r2347169048


##########
actor/src/main/scala/org/apache/pekko/japi/Throwables.scala:
##########
@@ -49,4 +49,15 @@ object Throwables {
    * or false if it is to be considered non-fatal
    */
   def isFatal(throwable: Throwable): Boolean = !isNonFatal(throwable)
+
+  /**
+   * Throws the given `Throwable`, without requiring the caller to declare it in a `throws` clause.
+   * @param t the `Throwable` to throw
+   * @throws T the type of the `Throwable` to throw

Review Comment:
   The `@throws T` documentation is incorrect. The method throws the actual `Throwable` instance `t`, not a type `T`. This should be `@throws t the `Throwable` instance to throw` or similar.
   ```suggestion
      * @throws t the `Throwable` instance to throw
   ```



##########
actor/src/main/scala/org/apache/pekko/japi/Throwables.scala:
##########
@@ -49,4 +49,15 @@ object Throwables {
    * or false if it is to be considered non-fatal
    */
   def isFatal(throwable: Throwable): Boolean = !isNonFatal(throwable)
+
+  /**
+   * Throws the given `Throwable`, without requiring the caller to declare it in a `throws` clause.
+   * @param t the `Throwable` to throw
+   * @throws T the type of the `Throwable` to throw
+   * @return never returns normally, but has return type `R` to allow usage in expressions
+   * @since 2.0.0
+   */
+  def sneakyThrow[T <: Throwable, R](t: Throwable): R = {
+    throw t.asInstanceOf[T]

Review Comment:
   The `asInstanceOf[T]` cast is unnecessary and potentially unsafe. Since `t` is already a `Throwable`, it should be thrown directly as `throw t`. The cast doesn't provide any benefit and could mask type issues.
   ```suggestion
       throw t
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat: Add sneakyThrow for Java [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #2218:
URL: https://github.com/apache/pekko/pull/2218#issuecomment-3312491801

   @mdedetrich The lombok and vavr both use this name, so it should be ok.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat: Add sneakyThrow for Java [pekko]

Posted by "mdedetrich (via GitHub)" <gi...@apache.org>.
mdedetrich commented on PR #2218:
URL: https://github.com/apache/pekko/pull/2218#issuecomment-3291330279

   Thanks, this is a better solution for providing throwable function interfaces in pekko API that doesn't allow it as its opt in by the user


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat: Add sneakyThrow for Java [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #2218:
URL: https://github.com/apache/pekko/pull/2218#issuecomment-3291354764

   That's true, this does not require a large refactoring.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat: Add sneakyThrow for Java [pekko]

Posted by "mdedetrich (via GitHub)" <gi...@apache.org>.
mdedetrich commented on PR #2218:
URL: https://github.com/apache/pekko/pull/2218#issuecomment-3314865728

   @He-Pin 
   
   Can you add docs for this new function? Also you can cherry pick both this and the docs to Pekko 1.x series since it's an addition


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat: Add sneakyThrow for Java [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin merged PR #2218:
URL: https://github.com/apache/pekko/pull/2218


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat: Add sneakyThrow for Java [pekko]

Posted by "mdedetrich (via GitHub)" <gi...@apache.org>.
mdedetrich commented on PR #2218:
URL: https://github.com/apache/pekko/pull/2218#issuecomment-3314870323

   > Don't find a good place to add
   
   Okay I can do it, don't forget to backport this


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] feat: Add sneakyThrow for Java [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #2218:
URL: https://github.com/apache/pekko/pull/2218#issuecomment-3314869759

   Don't find a good place to add


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org