From 42c2b493cbaf913b17cb204e4150084b56bc1ec3 Mon Sep 17 00:00:00 2001 From: "He-Pin(kerr)" Date: Fri, 12 Sep 2025 03:04:35 +0800 Subject: [PATCH] chore: Remove japi.option method (#2193) * chore: Remove japi.option method * . --- .../test/java/org/apache/pekko/actor/JavaAPI.java | 12 ------------ .../remove-deprecated-methods.excludes | 2 +- .../main/scala/org/apache/pekko/japi/JavaAPI.scala | 5 ----- .../persistence/snapshot/japi/SnapshotStore.scala | 7 ++++--- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/actor-tests/src/test/java/org/apache/pekko/actor/JavaAPI.java b/actor-tests/src/test/java/org/apache/pekko/actor/JavaAPI.java index a4a02f67b4..926e52a8f8 100644 --- a/actor-tests/src/test/java/org/apache/pekko/actor/JavaAPI.java +++ b/actor-tests/src/test/java/org/apache/pekko/actor/JavaAPI.java @@ -15,11 +15,9 @@ package org.apache.pekko.actor; import static org.junit.Assert.*; -import java.util.Optional; import org.apache.pekko.event.Logging; import org.apache.pekko.event.Logging.LoggerInitialized; import org.apache.pekko.japi.Pair; -import org.apache.pekko.japi.Util; import org.apache.pekko.japi.function.Creator; import org.apache.pekko.japi.tuple.Tuple22; import org.apache.pekko.japi.tuple.Tuple4; @@ -32,7 +30,6 @@ import org.apache.pekko.testkit.TestProbe; import org.junit.ClassRule; import org.junit.Test; import org.scalatestplus.junit.JUnitSuite; -import scala.Option; public class JavaAPI extends JUnitSuite { @@ -149,15 +146,6 @@ public class JavaAPI extends JUnitSuite { Tuple22.create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22); } - @Test - public void mustBeAbleToCreateOptionFromOptional() { - Option empty = Util.option(Optional.ofNullable(null)); - assertTrue(empty.isEmpty()); - - Option full = Util.option(Optional.ofNullable("hello")); - assertTrue(full.isDefined()); - } - public static class ActorWithConstructorParams extends UntypedAbstractActor { private final String a; diff --git a/actor/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes b/actor/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes index 64ebbaa2d3..88e60c1057 100644 --- a/actor/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes +++ b/actor/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes @@ -156,5 +156,5 @@ ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.dispatch.Th ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.event.LoggingBus.org$apache$pekko$event$LoggingBus$_setter_$org$apache$pekko$event$LoggingBus$$guard_=") ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.event.LoggingBus.org$apache$pekko$event$LoggingBus$$guard") ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.util.ReentrantGuard") - +ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.japi.Util.option") diff --git a/actor/src/main/scala/org/apache/pekko/japi/JavaAPI.scala b/actor/src/main/scala/org/apache/pekko/japi/JavaAPI.scala index 88c3351808..91c846a682 100644 --- a/actor/src/main/scala/org/apache/pekko/japi/JavaAPI.scala +++ b/actor/src/main/scala/org/apache/pekko/japi/JavaAPI.scala @@ -148,9 +148,4 @@ object Util { */ def immutableIndexedSeq[T](iterable: java.lang.Iterable[T]): immutable.IndexedSeq[T] = immutableSeq(iterable).toVector - - // TODO in case we decide to pull in scala-java8-compat methods below could be removed - https://github.com/akka/akka/issues/16247 - - def option[T](jOption: java.util.Optional[T]): scala.Option[T] = - scala.Option(jOption.orElse(null.asInstanceOf[T])) } diff --git a/persistence/src/main/scala/org/apache/pekko/persistence/snapshot/japi/SnapshotStore.scala b/persistence/src/main/scala/org/apache/pekko/persistence/snapshot/japi/SnapshotStore.scala index e7ca3bda55..cfab91bca9 100644 --- a/persistence/src/main/scala/org/apache/pekko/persistence/snapshot/japi/SnapshotStore.scala +++ b/persistence/src/main/scala/org/apache/pekko/persistence/snapshot/japi/SnapshotStore.scala @@ -17,7 +17,6 @@ import scala.concurrent.Future import org.apache.pekko import pekko.dispatch.ExecutionContexts -import pekko.japi.Util._ import pekko.persistence._ import pekko.persistence.snapshot.{ SnapshotStore => SSnapshotStore } import pekko.util.ConstantFun.scalaAnyToUnit @@ -30,8 +29,10 @@ abstract class SnapshotStore extends SSnapshotStore with SnapshotStorePlugin { override final def loadAsync( persistenceId: String, - criteria: SnapshotSelectionCriteria): Future[Option[SelectedSnapshot]] = - doLoadAsync(persistenceId, criteria).asScala.map(option)(ExecutionContexts.parasitic) + criteria: SnapshotSelectionCriteria): Future[Option[SelectedSnapshot]] = { + import pekko.util.OptionConverters._ + doLoadAsync(persistenceId, criteria).asScala.map(_.toScala)(ExecutionContexts.parasitic) + } override final def saveAsync(metadata: SnapshotMetadata, snapshot: Any): Future[Unit] = doSaveAsync(metadata, snapshot).asScala.map(scalaAnyToUnit)(ExecutionContexts.parasitic)