From 7346bda1764e713a0ee3cf6a12b06a9d23d6b46e Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Thu, 23 Mar 2023 17:47:56 +0100 Subject: [PATCH] Don't use deprecated SecurityManager, use StackWalker instead Have to fix this warning to fix compilation error in Jenkins See https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/493 --- .../internal/ui/javaeditor/JavaEditor.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java index b876c3022d5..500fde7e786 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java @@ -18,6 +18,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.ui.javaeditor; +import java.lang.StackWalker.StackFrame; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.text.CharacterIterator; @@ -27,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Predicate; import com.ibm.icu.text.BreakIterator; @@ -4249,19 +4251,17 @@ public JavaPairMatcher getBracketMatcher() { * @since 3.9 */ private static boolean isCalledByOutline() { - Class[] elements= new AccessChecker().getClassContext(); - for (int i= 0; i < elements.length && i < 10; i++) { - if (elements[i].equals(ContentOutline.class)) { - return true; - } - } - return false; + return OutlineAccessChecker.isCalledByOutline(); } - private static final class AccessChecker extends SecurityManager { - @Override - public Class[] getClassContext() { - return super.getClassContext(); + private static final class OutlineAccessChecker { + private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); + private static final String OUTLINE_NAME = ContentOutline.class.getCanonicalName(); + private static final Predicate CHECK_OUTLINE = frame -> OUTLINE_NAME.equals(frame.getClassName()); + + static boolean isCalledByOutline() { + Boolean wasCalled = STACK_WALKER.walk(fs -> Boolean.valueOf(fs.anyMatch(CHECK_OUTLINE))); + return wasCalled.booleanValue(); } }