chore: Remove SecurityManager usage. (#2106)
This commit is contained in:
parent
2a04e9649e
commit
273dc116d4
4 changed files with 44 additions and 51 deletions
|
|
@ -18,3 +18,4 @@
|
||||||
# Remove deprecated methods
|
# Remove deprecated methods
|
||||||
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.actor.typed.javadsl.TimerScheduler.startPeriodicTimer")
|
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.actor.typed.javadsl.TimerScheduler.startPeriodicTimer")
|
||||||
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.actor.typed.scaladsl.TimerScheduler.startPeriodicTimer")
|
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.actor.typed.scaladsl.TimerScheduler.startPeriodicTimer")
|
||||||
|
ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.actor.typed.internal.LoggerClass$TrickySecurityManager")
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,11 @@
|
||||||
|
|
||||||
package org.apache.pekko.actor.typed.internal
|
package org.apache.pekko.actor.typed.internal
|
||||||
|
|
||||||
import scala.annotation.nowarn
|
|
||||||
import scala.util.control.NonFatal
|
import scala.util.control.NonFatal
|
||||||
|
|
||||||
import org.apache.pekko
|
import org.apache.pekko
|
||||||
import pekko.annotation.InternalApi
|
import pekko.annotation.InternalApi
|
||||||
import pekko.util.OptionVal
|
import pekko.util.{ ClassContext, OptionVal }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL API
|
* INTERNAL API
|
||||||
|
|
@ -26,19 +25,12 @@ import pekko.util.OptionVal
|
||||||
@InternalApi
|
@InternalApi
|
||||||
private[pekko] object LoggerClass {
|
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")
|
private val defaultPrefixesToSkip = List("scala.runtime", "org.apache.pekko.actor.typed.internal")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to extract a logger class from the call stack, if not possible the provided default is used
|
* Try to extract a logger class from the call stack, if not possible the provided default is used
|
||||||
*/
|
*/
|
||||||
def detectLoggerClassFromStack(default: Class[_], additionalPrefixesToSkip: List[String] = Nil): Class[_] = {
|
def detectLoggerClassFromStack(default: Class[_], additionalPrefixesToSkip: List[String] = Nil): Class[_] = {
|
||||||
// TODO use stack walker API when we no longer need to support Java 8
|
|
||||||
try {
|
try {
|
||||||
def skip(name: String): Boolean = {
|
def skip(name: String): Boolean = {
|
||||||
def loop(skipList: List[String]): Boolean = skipList match {
|
def loop(skipList: List[String]): Boolean = skipList match {
|
||||||
|
|
@ -51,7 +43,7 @@ private[pekko] object LoggerClass {
|
||||||
loop(additionalPrefixesToSkip ::: defaultPrefixesToSkip)
|
loop(additionalPrefixesToSkip ::: defaultPrefixesToSkip)
|
||||||
}
|
}
|
||||||
|
|
||||||
val trace = new TrickySecurityManager().getClassStack
|
val trace = ClassContext.getClassStack
|
||||||
var suitableClass: OptionVal[Class[_]] = OptionVal.None
|
var suitableClass: OptionVal[Class[_]] = OptionVal.None
|
||||||
var idx = 1 // skip this method/class and right away
|
var idx = 1 // skip this method/class and right away
|
||||||
while (suitableClass.isEmpty && idx < trace.length) {
|
while (suitableClass.isEmpty && idx < trace.length) {
|
||||||
|
|
|
||||||
41
actor/src/main/java/org/apache/pekko/util/ClassContext.java
Normal file
41
actor/src/main/java/org/apache/pekko/util/ClassContext.java
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.pekko.util;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import org.apache.pekko.annotation.InternalApi;
|
||||||
|
|
||||||
|
/** INTERNAL API */
|
||||||
|
@InternalApi
|
||||||
|
public final class ClassContext {
|
||||||
|
private ClassContext() {
|
||||||
|
throw new UnsupportedOperationException("Cannot instantiate utility class");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Set<StackWalker.Option> OPTIONS =
|
||||||
|
Set.of(StackWalker.Option.RETAIN_CLASS_REFERENCE, StackWalker.Option.SHOW_HIDDEN_FRAMES);
|
||||||
|
|
||||||
|
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(OPTIONS).walk(CLASS_STACK_WALKER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue