Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8344795: Remove uses of AccessControlContext in java.desktop module #22308

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
Expand All @@ -62,8 +59,6 @@
* @see ElementHandler
*/
public final class DocumentHandler extends DefaultHandler {
@SuppressWarnings("removal")
private final AccessControlContext acc = AccessController.getContext();
private final Map<String, Class<? extends ElementHandler>> handlers = new HashMap<>();
private final Map<String, Object> environment = new HashMap<>();
private final List<Object> objects = new ArrayList<>();
Expand Down Expand Up @@ -367,30 +362,20 @@ public void handleException(Exception exception) {
*
* @param input the input source to parse
*/
@SuppressWarnings("removal")
public void parse(final InputSource input) {
if ((this.acc == null) && (null != System.getSecurityManager())) {
throw new SecurityException("AccessControlContext is not set");
try {
SAXParserFactory.newInstance().newSAXParser().parse(input, DocumentHandler.this);
}
AccessControlContext stack = AccessController.getContext();
SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Void>() {
public Void run() {
try {
SAXParserFactory.newInstance().newSAXParser().parse(input, DocumentHandler.this);
}
catch (ParserConfigurationException | IOException exception) {
handleException(exception);
}
catch (SAXException wrapper) {
Exception exception = wrapper.getException();
if (exception == null) {
exception = wrapper;
}
handleException(exception);
}
return null;
catch (ParserConfigurationException | IOException exception) {
handleException(exception);
}
catch (SAXException wrapper) {
Exception exception = wrapper.getException();
if (exception == null) {
exception = wrapper;
}
}, stack, this.acc);
handleException(exception);
}
}

/**
Expand Down
25 changes: 0 additions & 25 deletions src/java.desktop/share/classes/java/awt/AWTEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import java.awt.peer.ComponentPeer;
import java.awt.peer.LightweightPeer;
import java.io.Serial;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.EventObject;

import sun.awt.AWTAccessor;
Expand Down Expand Up @@ -112,24 +110,6 @@ public abstract class AWTEvent extends EventObject {
*/
protected boolean consumed = false;

/*
* The event's AccessControlContext.
*/
@SuppressWarnings("removal")
private transient volatile AccessControlContext acc =
AccessController.getContext();

/*
* Returns the acc this event was constructed with.
*/
@SuppressWarnings("removal")
final AccessControlContext getAccessControlContext() {
if (acc == null) {
throw new SecurityException("AWTEvent is missing AccessControlContext");
}
return acc;
}

transient boolean focusManagerIsDispatching = false;
transient boolean isPosted;

Expand Down Expand Up @@ -281,11 +261,6 @@ public boolean isSystemGenerated(AWTEvent ev) {
return ev.isSystemGenerated;
}

@SuppressWarnings("removal")
public AccessControlContext getAccessControlContext(AWTEvent ev) {
return ev.getAccessControlContext();
}

public byte[] getBData(AWTEvent ev) {
return ev.bdata;
}
Expand Down
28 changes: 0 additions & 28 deletions src/java.desktop/share/classes/java/awt/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
import java.io.PrintWriter;
import java.io.Serial;
import java.io.Serializable;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.Collections;
import java.util.EventListener;
import java.util.HashSet;
Expand Down Expand Up @@ -501,13 +499,6 @@ public abstract class Component implements ImageObserver, MenuContainer,
static final Object LOCK = new AWTTreeLock();
static class AWTTreeLock {}

/*
* The component's AccessControlContext.
*/
@SuppressWarnings("removal")
private transient volatile AccessControlContext acc =
AccessController.getContext();

/**
* Minimum size.
* (This field perhaps should have been transient).
Expand Down Expand Up @@ -706,17 +697,6 @@ Object getObjectLock() {
return objectLock;
}

/*
* Returns the acc this component was constructed with.
*/
@SuppressWarnings("removal")
final AccessControlContext getAccessControlContext() {
if (acc == null) {
throw new SecurityException("Component is missing AccessControlContext");
}
return acc;
}

/**
* Whether the component is packed or not;
*/
Expand Down Expand Up @@ -972,11 +952,6 @@ public void processEvent(Component comp, AWTEvent e) {
comp.processEvent(e);
}

@SuppressWarnings("removal")
public AccessControlContext getAccessControlContext(Component comp) {
return comp.getAccessControlContext();
}

public void revalidateSynchronously(Component comp) {
comp.revalidateSynchronously();
}
Expand Down Expand Up @@ -8967,15 +8942,12 @@ private void writeObject(ObjectOutputStream s)
* @throws IOException if an I/O error occurs
* @see #writeObject(ObjectOutputStream)
*/
@SuppressWarnings("removal")
@Serial
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException
{
prrace marked this conversation as resolved.
Show resolved Hide resolved
objectLock = new Object();

acc = AccessController.getContext();

s.defaultReadObject();

appContext = AppContext.getAppContext();
Expand Down
24 changes: 0 additions & 24 deletions src/java.desktop/share/classes/java/awt/MenuComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serial;
import java.security.AccessControlContext;
import java.security.AccessController;

import javax.accessibility.Accessible;
import javax.accessibility.AccessibleComponent;
Expand Down Expand Up @@ -103,25 +101,6 @@ public abstract class MenuComponent implements java.io.Serializable {
*/
volatile boolean newEventsOnly;

/*
* The menu's AccessControlContext.
*/
@SuppressWarnings("removal")
private transient volatile AccessControlContext acc =
AccessController.getContext();

/*
* Returns the acc this menu component was constructed with.
*/
@SuppressWarnings("removal")
final AccessControlContext getAccessControlContext() {
if (acc == null) {
throw new SecurityException(
"MenuComponent is missing AccessControlContext");
}
return acc;
}

/*
* Internal constants for serialization.
*/
Expand Down Expand Up @@ -442,15 +421,12 @@ protected final Object getTreeLock() {
*
* @see java.awt.GraphicsEnvironment#isHeadless
*/
@SuppressWarnings("removal")
@Serial
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException, HeadlessException
{
prrace marked this conversation as resolved.
Show resolved Hide resolved
GraphicsEnvironment.checkHeadless();

acc = AccessController.getContext();

s.defaultReadObject();

appContext = AppContext.getAppContext();
Expand Down
22 changes: 0 additions & 22 deletions src/java.desktop/share/classes/java/awt/TrayIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import sun.awt.AWTAccessor;
import sun.awt.HeadlessToolkit;
import java.util.EventObject;
import java.security.AccessControlContext;
import java.security.AccessController;

/**
* A {@code TrayIcon} object represents a tray icon that can be
Expand Down Expand Up @@ -102,26 +100,6 @@ public class TrayIcon {
transient MouseMotionListener mouseMotionListener;
transient ActionListener actionListener;

/*
* The tray icon's AccessControlContext.
*
* Unlike the acc in Component, this field is made final
* because TrayIcon is not serializable.
*/
@SuppressWarnings("removal")
private final AccessControlContext acc = AccessController.getContext();

/*
* Returns the acc this tray icon was constructed with.
*/
@SuppressWarnings("removal")
final AccessControlContext getAccessControlContext() {
if (acc == null) {
throw new SecurityException("TrayIcon is missing AccessControlContext");
}
return acc;
}

static {
Toolkit.loadLibraries();
if (!GraphicsEnvironment.isHeadless()) {
Expand Down
43 changes: 0 additions & 43 deletions src/java.desktop/share/classes/javax/swing/TransferHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@
import sun.swing.*;
import sun.awt.SunToolkit;

import java.security.AccessController;
import java.security.PrivilegedAction;

import java.security.AccessControlContext;

import jdk.internal.access.SharedSecrets;
import jdk.internal.access.JavaSecurityAccess;

import sun.awt.AWTAccessor;

/**
* This class is used to handle the transfer of a <code>Transferable</code>
* to and from Swing components. The <code>Transferable</code> is used to
Expand Down Expand Up @@ -1701,40 +1691,7 @@ public boolean accept(Object sender) {
&& ((JComponent)sender).getTransferHandler() == null);
}

private static final JavaSecurityAccess javaSecurityAccess =
SharedSecrets.getJavaSecurityAccess();

public void actionPerformed(final ActionEvent e) {
final Object src = e.getSource();

final PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
public Void run() {
actionPerformedImpl(e);
return null;
}
};

@SuppressWarnings("removal")
final AccessControlContext stack = AccessController.getContext();
@SuppressWarnings("removal")
final AccessControlContext srcAcc = AWTAccessor.getComponentAccessor().getAccessControlContext((Component)src);
@SuppressWarnings("removal")
final AccessControlContext eventAcc = AWTAccessor.getAWTEventAccessor().getAccessControlContext(e);

if (srcAcc == null) {
javaSecurityAccess.doIntersectionPrivilege(action, stack, eventAcc);
} else {
javaSecurityAccess.doIntersectionPrivilege(
new PrivilegedAction<Void>() {
public Void run() {
javaSecurityAccess.doIntersectionPrivilege(action, eventAcc);
return null;
}
}, stack, srcAcc);
}
}

private void actionPerformedImpl(ActionEvent e) {
Object src = e.getSource();
if (src instanceof JComponent) {
JComponent c = (JComponent) src;
Expand Down
6 changes: 0 additions & 6 deletions src/java.desktop/share/classes/javax/swing/UIDefaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import java.awt.Insets;
import java.awt.Dimension;
import java.beans.PropertyChangeListener;
import java.security.AccessController;
import java.security.AccessControlContext;

import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;
Expand Down Expand Up @@ -1062,8 +1060,6 @@ public interface ActiveValue {
* @since 1.3
*/
public static class ProxyLazyValue implements LazyValue {
@SuppressWarnings("removal")
private AccessControlContext acc;
private String className;
private String methodName;
private Object[] args;
Expand Down Expand Up @@ -1117,9 +1113,7 @@ public ProxyLazyValue(String c, Object[] o) {
* @param o an array of <code>Objects</code> to be passed as
* parameters to the static method in class c
*/
@SuppressWarnings("removal")
public ProxyLazyValue(String c, String m, Object[] o) {
acc = AccessController.getContext();
className = c;
methodName = m;
if (o != null) {
Expand Down
14 changes: 0 additions & 14 deletions src/java.desktop/share/classes/sun/awt/AWTAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.awt.peer.MenuComponentPeer;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessControlContext;

import java.io.File;
import java.util.ResourceBundle;
Expand Down Expand Up @@ -244,13 +243,6 @@ public interface ComponentAccessor {
*/
void processEvent(Component comp, AWTEvent e);


/*
* Returns the acc this component was constructed with.
*/
@SuppressWarnings("removal")
AccessControlContext getAccessControlContext(Component comp);

/**
* Revalidates the component synchronously.
*/
Expand Down Expand Up @@ -364,12 +356,6 @@ public interface AWTEventAccessor {
*/
boolean isSystemGenerated(AWTEvent ev);

/**
* Returns the acc this event was constructed with.
*/
@SuppressWarnings("removal")
AccessControlContext getAccessControlContext(AWTEvent ev);

/**
* Returns binary data associated with this event;
*/
Expand Down