Skip to content

Commit

Permalink
8342993: Remove uses of AccessController and AccessControlContext fro…
Browse files Browse the repository at this point in the history
…m JavaFX

Reviewed-by: angorya, mstrauss
  • Loading branch information
kevinrushforth committed Nov 18, 2024
1 parent dd60065 commit 7d1b2c3
Show file tree
Hide file tree
Showing 30 changed files with 66 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public final class JavaBeanIntegerProperty extends IntegerProperty implements Ja
* property throws an {@code IllegalAccessException} or an
* {@code InvocationTargetException}.
*/
@SuppressWarnings("removal")
@Override
public int get() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import static javafx.scene.AccessibleAttribute.PARENT;
import static javafx.scene.AccessibleAttribute.ROLE;
import java.security.AccessControlContext;
import com.sun.javafx.scene.NodeHelper;
import com.sun.javafx.scene.SceneHelper;
import com.sun.javafx.tk.quantum.QuantumToolkit;
Expand All @@ -51,9 +50,6 @@ public Object getAttribute(AccessibleAttribute attribute, Object... parameters)

public void executeAction(AccessibleAction action, Object... parameters) {
}

@SuppressWarnings("removal")
public abstract AccessControlContext getAccessControlContext();
}

public EventHandler getEventHandler() {
Expand Down Expand Up @@ -122,21 +118,6 @@ protected Accessible getContainerAccessible(AccessibleRole targetRole) {
return null;
}

/*
* IMPORTANT: Calling to the user code should not proceed if
* this method returns NULL.
*/
@SuppressWarnings("removal")
private final AccessControlContext getAccessControlContext() {
AccessControlContext acc = null;
try {
acc = eventHandler.getAccessControlContext();
} catch (Exception e) {
/* The node was already removed from the scene */
}
return acc;
}

private class GetAttribute implements Supplier<Object> {
AccessibleAttribute attribute;
Object[] parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ private void doVisibleChanging(boolean visible) {
Toolkit toolkit = Toolkit.getToolkit();
if (visible && (WindowHelper.getPeer(this) == null)) {
// Setup the peer
WindowHelper.setPeer(this, toolkit.createTKEmbeddedStage(host,
WindowHelper.getAccessControlContext(this)));
WindowHelper.setPeer(this, toolkit.createTKEmbeddedStage(host));
WindowHelper.setPeerListener(this, new WindowPeerListener(this));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import javafx.stage.Screen;
import javafx.stage.Window;

import java.security.AccessControlContext;

/**
* Used to access internal window methods.
*/
Expand Down Expand Up @@ -130,11 +128,6 @@ public static void notifyScaleChanged(final Window window,
windowAccessor.notifyScaleChanged(window, newOutputScaleX, newOutputScaleY);
}

@SuppressWarnings("removal")
static AccessControlContext getAccessControlContext(Window window) {
return windowAccessor.getAccessControlContext(window);
}

public static void setWindowAccessor(final WindowAccessor newAccessor) {
if (windowAccessor != null) {
throw new IllegalStateException();
Expand Down Expand Up @@ -169,8 +162,5 @@ public interface WindowAccessor {
void notifyScaleChanged(Window window, double newOutputScaleX, double newOutputScaleY);

ReadOnlyObjectProperty<Screen> screenProperty(Window window);

@SuppressWarnings("removal")
AccessControlContext getAccessControlContext(Window window);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import javafx.stage.Window;
import java.io.File;
import java.io.InputStream;
import java.security.AccessControlContext;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -102,17 +101,17 @@ public void exitAllNestedEventLoops() {
}

@Override
public TKStage createTKStage(Window peerWindow, boolean securityDialog, StageStyle stageStyle, boolean primary, Modality modality, TKStage owner, boolean rtl, @SuppressWarnings("removal") AccessControlContext acc) {
public TKStage createTKStage(Window peerWindow, boolean securityDialog, StageStyle stageStyle, boolean primary, Modality modality, TKStage owner, boolean rtl) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public TKStage createTKPopupStage(Window peerWindow, StageStyle popupStyle, TKStage owner, @SuppressWarnings("removal") AccessControlContext acc) {
public TKStage createTKPopupStage(Window peerWindow, StageStyle popupStyle, TKStage owner) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public TKStage createTKEmbeddedStage(HostInterface host, @SuppressWarnings("removal") AccessControlContext acc) {
public TKStage createTKEmbeddedStage(HostInterface host) {
throw new UnsupportedOperationException("Not supported yet.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package com.sun.javafx.tk;

import java.security.AccessControlContext;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -43,11 +42,6 @@ public LocalClipboard() {
values = new HashMap<>();
}

@Override
public void setSecurityContext(@SuppressWarnings("removal") final AccessControlContext ctx) {
// ctx not needed
}

@Override
public Set<DataFormat> getContentTypes() {
return Collections.unmodifiableSet(new HashSet<>(values.keySet()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package com.sun.javafx.tk;

import java.security.AccessControlContext;
import java.util.Set;
import javafx.scene.image.Image;

Expand All @@ -40,11 +39,6 @@
*/
public interface TKClipboard {

/**
* This method is used to set security context of the Stage.
*/
public void setSecurityContext(@SuppressWarnings("removal") AccessControlContext ctx);

/**
* Gets the set of DataFormat types on this Clipboard instance which have
* associated data registered on the clipboard. This set will always
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package com.sun.javafx.tk;

import java.security.AccessControlContext;
import com.sun.javafx.sg.prism.NGCamera;
import com.sun.javafx.sg.prism.NGLightBase;
import com.sun.javafx.sg.prism.NGNode;
Expand Down Expand Up @@ -86,7 +85,4 @@ public interface TKScene {
public void entireSceneNeedsRepaint();

public TKClipboard createDragboard(boolean isDragSource);

@SuppressWarnings("removal")
public AccessControlContext getAccessControlContext();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package com.sun.javafx.tk;

import java.security.AccessControlContext;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination.ModifierValue;
Expand All @@ -47,7 +46,7 @@ public interface TKStage {
*
* @return scenePeer The peer of the scene to be displayed
*/
public TKScene createTKScene(boolean depthBuffer, boolean msaa, @SuppressWarnings("removal") AccessControlContext acc);
public TKScene createTKScene(boolean depthBuffer, boolean msaa);

/**
* Set the scene to be displayed in this stage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@
import java.io.File;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -211,9 +210,7 @@ public static synchronized Toolkit getToolkit() {

// Check a system property to see if there is a specific toolkit to use.
String forcedToolkit = null;
try {
forcedToolkit = System.getProperty("javafx.toolkit");
} catch (SecurityException ex) {}
forcedToolkit = System.getProperty("javafx.toolkit");

if (forcedToolkit == null) {
forcedToolkit = tk;
Expand Down Expand Up @@ -363,76 +360,60 @@ protected Toolkit() {

public abstract boolean isNestedLoopRunning();

public abstract TKStage createTKStage(Window peerWindow, boolean securityDialog, StageStyle stageStyle, boolean primary, Modality modality, TKStage owner, boolean rtl, @SuppressWarnings("removal") AccessControlContext acc);
public abstract TKStage createTKStage(Window peerWindow, boolean securityDialog, StageStyle stageStyle, boolean primary, Modality modality, TKStage owner, boolean rtl);

public abstract TKStage createTKPopupStage(Window peerWindow, StageStyle popupStyle, TKStage owner, @SuppressWarnings("removal") AccessControlContext acc);
public abstract TKStage createTKEmbeddedStage(HostInterface host, @SuppressWarnings("removal") AccessControlContext acc);
public abstract TKStage createTKPopupStage(Window peerWindow, StageStyle popupStyle, TKStage owner);
public abstract TKStage createTKEmbeddedStage(HostInterface host);

@SuppressWarnings("removal")
private final Map<TKPulseListener,AccessControlContext> stagePulseListeners = new WeakHashMap<>();
@SuppressWarnings("removal")
private final Map<TKPulseListener,AccessControlContext> scenePulseListeners = new WeakHashMap<>();
@SuppressWarnings("removal")
private final Map<TKPulseListener,AccessControlContext> postScenePulseListeners = new WeakHashMap<>();
@SuppressWarnings("removal")
private final Map<TKListener,AccessControlContext> toolkitListeners = new WeakHashMap<>();
// The following collections of listeners is weakly referenced here in order
// to allow garbage collection when the listeners are otherwise no longer
// referenced.
private final Set<TKPulseListener> stagePulseListeners = Collections.newSetFromMap(new WeakHashMap<>());
private final Set<TKPulseListener> scenePulseListeners = Collections.newSetFromMap(new WeakHashMap<>());
private final Set<TKPulseListener> postScenePulseListeners = Collections.newSetFromMap(new WeakHashMap<>());
private final Set<TKListener> toolkitListeners = Collections.newSetFromMap(new WeakHashMap<>());

// The set of shutdown hooks is strongly held to avoid premature GC.
private final Set<Runnable> shutdownHooks = new HashSet<>();

@SuppressWarnings("removal")
private void runPulse(final TKPulseListener listener,
final AccessControlContext acc) {

if (acc == null) {
throw new IllegalStateException("Invalid AccessControlContext");
}

private void runPulse(final TKPulseListener listener) {
listener.pulse();
}

public void firePulse() {
// Stages need to be notified of pulses before scenes so the Stage can resized
// and those changes propogated to scene before it gets its pulse to update

// Copy of listener map
@SuppressWarnings("removal")
final Map<TKPulseListener,AccessControlContext> stagePulseList =
new WeakHashMap<>();
@SuppressWarnings("removal")
final Map<TKPulseListener,AccessControlContext> scenePulseList =
new WeakHashMap<>();
@SuppressWarnings("removal")
final Map<TKPulseListener,AccessControlContext> postScenePulseList =
new WeakHashMap<>();
// Copy of listener keySet
final Set<TKPulseListener> stagePulseList = new HashSet<>();
final Set<TKPulseListener> scenePulseList = new HashSet<>();
final Set<TKPulseListener> postScenePulseList = new HashSet<>();

synchronized (this) {
stagePulseList.putAll(stagePulseListeners);
scenePulseList.putAll(scenePulseListeners);
postScenePulseList.putAll(postScenePulseListeners);
stagePulseList.addAll(stagePulseListeners);
scenePulseList.addAll(scenePulseListeners);
postScenePulseList.addAll(postScenePulseListeners);
}
for (@SuppressWarnings("removal") Map.Entry<TKPulseListener,AccessControlContext> entry : stagePulseList.entrySet()) {
runPulse(entry.getKey(), entry.getValue());
for (TKPulseListener listener : stagePulseList) {
runPulse(listener);
}
for (@SuppressWarnings("removal") Map.Entry<TKPulseListener,AccessControlContext> entry : scenePulseList.entrySet()) {
runPulse(entry.getKey(), entry.getValue());
for (TKPulseListener listener : scenePulseList) {
runPulse(listener);
}
for (@SuppressWarnings("removal") Map.Entry<TKPulseListener,AccessControlContext> entry : postScenePulseList.entrySet()) {
runPulse(entry.getKey(), entry.getValue());
for (TKPulseListener listener : postScenePulseList) {
runPulse(listener);
}

if (lastTkPulseListener != null) {
runPulse(lastTkPulseListener, lastTkPulseAcc);
runPulse(lastTkPulseListener);
}
}
public void addStageTkPulseListener(TKPulseListener listener) {
if (listener == null) {
return;
}
synchronized (this) {
@SuppressWarnings("removal")
AccessControlContext acc = AccessController.getContext();
stagePulseListeners.put(listener, acc);
stagePulseListeners.add(listener);
}
}
public void removeStageTkPulseListener(TKPulseListener listener) {
Expand All @@ -445,9 +426,7 @@ public void addSceneTkPulseListener(TKPulseListener listener) {
return;
}
synchronized (this) {
@SuppressWarnings("removal")
AccessControlContext acc = AccessController.getContext();
scenePulseListeners.put(listener, acc);
scenePulseListeners.add(listener);
}
}
public void removeSceneTkPulseListener(TKPulseListener listener) {
Expand All @@ -460,9 +439,7 @@ public void addPostSceneTkPulseListener(TKPulseListener listener) {
return;
}
synchronized (this) {
@SuppressWarnings("removal")
AccessControlContext acc = AccessController.getContext();
postScenePulseListeners.put(listener, acc);
postScenePulseListeners.add(listener);
}
}
public void removePostSceneTkPulseListener(TKPulseListener listener) {
Expand All @@ -475,21 +452,16 @@ public void addTkListener(TKListener listener) {
if (listener == null) {
return;
}
@SuppressWarnings("removal")
AccessControlContext acc = AccessController.getContext();
toolkitListeners.put(listener, acc);
toolkitListeners.add(listener);
}

public void removeTkListener(TKListener listener) {
toolkitListeners.remove(listener);
}

private TKPulseListener lastTkPulseListener = null;
@SuppressWarnings("removal")
private AccessControlContext lastTkPulseAcc = null;
@SuppressWarnings("removal")

public void setLastTkPulseListener(TKPulseListener listener) {
lastTkPulseAcc = AccessController.getContext();
lastTkPulseListener = listener;
}

Expand Down Expand Up @@ -521,13 +493,13 @@ protected void notifyShutdownHooks() {
}

public void notifyWindowListeners(final List<TKStage> windows) {
for (TKListener listener : toolkitListeners.keySet()) {
for (TKListener listener : toolkitListeners) {
listener.changedTopLevelWindows(windows);
}
}

public void notifyLastNestedLoopExited() {
for (TKListener listener: toolkitListeners.keySet()) {
for (TKListener listener: toolkitListeners) {
listener.exitedLastNestedLoop();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package com.sun.javafx.tk.quantum;

import java.security.AccessControlContext;
import java.util.List;

import com.sun.javafx.embed.AbstractEvents;
Expand All @@ -46,10 +45,8 @@ public EmbeddedStage(HostInterface host) {
// TKStage methods

@Override
public TKScene createTKScene(boolean depthBuffer, boolean msaa, @SuppressWarnings("removal") AccessControlContext acc) {
EmbeddedScene scene = new EmbeddedScene(host, depthBuffer, msaa);
scene.setSecurityContext(acc);
return scene;
public TKScene createTKScene(boolean depthBuffer, boolean msaa) {
return new EmbeddedScene(host, depthBuffer, msaa);
}

@Override
Expand Down
Loading

1 comment on commit 7d1b2c3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.