You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by he...@apache.org on 2025/08/30 04:40:50 UTC
(pekko) 01/01: chore: Remove SecurityManager usage.
This is an automated email from the ASF dual-hosted git repository.
hepin pushed a commit to branch sec
in repository https://gitbox.apache.org/repos/asf/pekko.git
commit 53833eb3a27e35bc2d1983ec898f9f11a4eb0a5b
Author: He-Pin <he...@gmail.com>
AuthorDate: Sat Aug 30 12:40:34 2025 +0800
chore: Remove SecurityManager usage.
---
.../remove-deprecated-methods.excludes | 1 +
.../pekko/actor/typed/internal/LoggerClass.scala | 11 ++----
.../java/org/apache/pekko/util/ClassContext.java | 18 ++++++++++
.../scala/org/apache/pekko/util/StackBench.scala | 41 ----------------------
4 files changed, 21 insertions(+), 50 deletions(-)
diff --git a/actor-typed/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes b/actor-typed/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes
index c301da7df2..16fc80b4ab 100644
--- a/actor-typed/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes
+++ b/actor-typed/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes
@@ -18,3 +18,4 @@
# Remove deprecated methods
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.actor.typed.javadsl.TimerScheduler.startPeriodicTimer")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.actor.typed.scaladsl.TimerScheduler.startPeriodicTimer")
+ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.actor.typed.internal.LoggerClass$TrickySecurityManager")
diff --git a/actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/LoggerClass.scala b/actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/LoggerClass.scala
index a62e0b350a..18f5e01cc2 100644
--- a/actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/LoggerClass.scala
+++ b/actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/LoggerClass.scala
@@ -13,12 +13,11 @@
package org.apache.pekko.actor.typed.internal
-import scala.annotation.nowarn
import scala.util.control.NonFatal
import org.apache.pekko
import pekko.annotation.InternalApi
-import pekko.util.OptionVal
+import pekko.util.{ ClassContext, OptionVal }
/**
* INTERNAL API
@@ -26,12 +25,6 @@ import pekko.util.OptionVal
@InternalApi
private[pekko] object LoggerClass {
- // just to get access to the class context
- @nowarn("msg=deprecated")
- private final class TrickySecurityManager extends SecurityManager {
- def getClassStack: Array[Class[_]] = getClassContext
- }
-
private val defaultPrefixesToSkip = List("scala.runtime", "org.apache.pekko.actor.typed.internal")
/**
@@ -51,7 +44,7 @@ private[pekko] object LoggerClass {
loop(additionalPrefixesToSkip ::: defaultPrefixesToSkip)
}
- val trace = new TrickySecurityManager().getClassStack
+ val trace = ClassContext.getClassStack
var suitableClass: OptionVal[Class[_]] = OptionVal.None
var idx = 1 // skip this method/class and right away
while (suitableClass.isEmpty && idx < trace.length) {
diff --git a/actor/src/main/java/org/apache/pekko/util/ClassContext.java b/actor/src/main/java/org/apache/pekko/util/ClassContext.java
new file mode 100644
index 0000000000..947e9c1063
--- /dev/null
+++ b/actor/src/main/java/org/apache/pekko/util/ClassContext.java
@@ -0,0 +1,18 @@
+package org.apache.pekko.util;
+
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+public final class ClassContext {
+ private ClassContext() {
+ throw new UnsupportedOperationException("Cannot instantiate utility class");
+ }
+
+ private static final Function<Stream<StackWalker.StackFrame>, Class<?>[]> CLASS_STACK_WALKER =
+ frames -> frames.map(StackWalker.StackFrame::getDeclaringClass).toArray(Class<?>[]::new);
+
+ public static Class<?>[] getClassStack() {
+ return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE)
+ .walk(CLASS_STACK_WALKER);
+ }
+}
diff --git a/bench-jmh/src/main/scala/org/apache/pekko/util/StackBench.scala b/bench-jmh/src/main/scala/org/apache/pekko/util/StackBench.scala
deleted file mode 100644
index d427426785..0000000000
--- a/bench-jmh/src/main/scala/org/apache/pekko/util/StackBench.scala
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * license agreements; and to You under the Apache License, version 2.0:
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * This file is part of the Apache Pekko project, which was derived from Akka.
- */
-
-/*
- * Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
- */
-
-package org.apache.pekko.util
-
-import java.util.concurrent.TimeUnit
-import scala.annotation.nowarn
-
-import org.openjdk.jmh.annotations.{ Benchmark, Measurement, Scope, State }
-
-@State(Scope.Benchmark)
-@Measurement(timeUnit = TimeUnit.MICROSECONDS)
-class StackBench {
-
- @nowarn("msg=deprecated")
- class CustomSecurtyManager extends SecurityManager {
- def getTrace: Array[Class[_]] =
- getClassContext
- }
-
- @Benchmark
- def currentThread(): Array[StackTraceElement] = {
- Thread.currentThread().getStackTrace
- }
-
- @Benchmark
- def securityManager(): Array[Class[_]] = {
- (new CustomSecurtyManager).getTrace
- }
-
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org