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

8267521: Post JEP 411 refactoring: maximum covering > 50K #4138

Closed
wants to merge 1 commit 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
13 changes: 11 additions & 2 deletions src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
* @since 1.7
* @author Doug Lea
*/
@SuppressWarnings("removal")
public class ForkJoinPool extends AbstractExecutorService {

/*
Expand Down Expand Up @@ -751,11 +750,13 @@ public class ForkJoinPool extends AbstractExecutorService {
* permission to modify threads.
*/
private static void checkPermission() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkPermission(modifyThreadPermission);
}

@SuppressWarnings("removal")
static AccessControlContext contextWithPermissions(Permission ... perms) {
Permissions permissions = new Permissions();
for (Permission perm : perms)
Expand Down Expand Up @@ -799,9 +800,11 @@ public static interface ForkJoinWorkerThreadFactory {
static final class DefaultForkJoinWorkerThreadFactory
implements ForkJoinWorkerThreadFactory {
// ACC for access to the factory
@SuppressWarnings("removal")
private static final AccessControlContext ACC = contextWithPermissions(
new RuntimePermission("getClassLoader"),
new RuntimePermission("setContextClassLoader"));
@SuppressWarnings("removal")
public final ForkJoinWorkerThread newThread(ForkJoinPool pool) {
return AccessController.doPrivileged(
new PrivilegedAction<>() {
Expand All @@ -821,13 +824,15 @@ public ForkJoinWorkerThread run() {
*/
static final class DefaultCommonPoolForkJoinWorkerThreadFactory
implements ForkJoinWorkerThreadFactory {
@SuppressWarnings("removal")
private static final AccessControlContext ACC = contextWithPermissions(
modifyThreadPermission,
new RuntimePermission("enableContextClassLoaderOverride"),
new RuntimePermission("modifyThreadGroup"),
new RuntimePermission("getClassLoader"),
new RuntimePermission("setContextClassLoader"));

@SuppressWarnings("removal")
public final ForkJoinWorkerThread newThread(ForkJoinPool pool) {
return AccessController.doPrivileged(
new PrivilegedAction<>() {
Expand Down Expand Up @@ -1253,11 +1258,13 @@ final void helpAsyncBlocker(ManagedBlocker blocker) {
// misc

/** AccessControlContext for innocuous workers, created on 1st use. */
@SuppressWarnings("removal")
private static AccessControlContext INNOCUOUS_ACC;

/**
* Initializes (upon registration) InnocuousForkJoinWorkerThreads.
*/
@SuppressWarnings("removal")
final void initializeInnocuousWorker() {
AccessControlContext acc; // racy construction OK
if ((acc = INNOCUOUS_ACC) == null)
Expand Down Expand Up @@ -3497,9 +3504,11 @@ protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
defaultForkJoinWorkerThreadFactory =
new DefaultForkJoinWorkerThreadFactory();
modifyThreadPermission = new RuntimePermission("modifyThread");
common = AccessController.doPrivileged(new PrivilegedAction<>() {
@SuppressWarnings("removal")
ForkJoinPool tmp = AccessController.doPrivileged(new PrivilegedAction<>() {
public ForkJoinPool run() {
return new ForkJoinPool((byte)0); }});
common = tmp;

COMMON_PARALLELISM = Math.max(common.mode & SMASK, 1);
}
Expand Down
48 changes: 17 additions & 31 deletions src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import sun.util.logging.PlatformLogger;


@SuppressWarnings("removal")
public class FtpClient extends sun.net.ftp.FtpClient {

private static int defaultSoTimeout;
Expand Down Expand Up @@ -111,16 +110,13 @@ public class FtpClient extends sun.net.ftp.FtpClient {

static {
final int vals[] = {0, 0};
final String encs[] = {null};

AccessController.doPrivileged(
new PrivilegedAction<Object>() {

public Object run() {
@SuppressWarnings("removal")
final String enc = AccessController.doPrivileged(
new PrivilegedAction<String>() {
public String run() {
vals[0] = Integer.getInteger("sun.net.client.defaultReadTimeout", 300_000).intValue();
vals[1] = Integer.getInteger("sun.net.client.defaultConnectTimeout", 300_000).intValue();
encs[0] = System.getProperty("file.encoding", "ISO8859_1");
return null;
return System.getProperty("file.encoding", "ISO8859_1");
}
Comment on lines +113 to 120
Copy link
Member

Choose a reason for hiding this comment

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

It is a bit strange that "file.encoding" seem to get a special treatment - but I guess that's OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You might say we thus avoid wasting the return value, as much as possible.

});
if (vals[0] == 0) {
Expand All @@ -135,7 +131,7 @@ public Object run() {
defaultConnectTimeout = vals[1];
}

encoding = encs[0];
encoding = enc;
try {
if (!isASCIISuperset(encoding)) {
encoding = "ISO8859_1";
Expand Down Expand Up @@ -632,27 +628,20 @@ private Socket openPassiveDataConnection(String cmd) throws sun.net.ftp.FtpProto
Socket s;
if (proxy != null) {
if (proxy.type() == Proxy.Type.SOCKS) {
s = AccessController.doPrivileged(
new PrivilegedAction<Socket>() {

public Socket run() {
return new Socket(proxy);
}
});
PrivilegedAction<Socket> pa = () -> new Socket(proxy);
@SuppressWarnings("removal")
var tmp = AccessController.doPrivileged(pa);
s = tmp;
} else {
s = new Socket(Proxy.NO_PROXY);
}
} else {
s = new Socket();
}

InetAddress serverAddress = AccessController.doPrivileged(
new PrivilegedAction<InetAddress>() {
@Override
public InetAddress run() {
return server.getLocalAddress();
}
});
PrivilegedAction<InetAddress> pa = () -> server.getLocalAddress();
@SuppressWarnings("removal")
InetAddress serverAddress = AccessController.doPrivileged(pa);

// Bind the socket to the same address as the control channel. This
// is needed in case of multi-homed systems.
Expand Down Expand Up @@ -925,13 +914,10 @@ private Socket doConnect(InetSocketAddress dest, int timeout) throws IOException
Socket s;
if (proxy != null) {
if (proxy.type() == Proxy.Type.SOCKS) {
s = AccessController.doPrivileged(
new PrivilegedAction<Socket>() {

public Socket run() {
return new Socket(proxy);
}
});
PrivilegedAction<Socket> pa = () -> new Socket(proxy);
@SuppressWarnings("removal")
var tmp = AccessController.doPrivileged(pa);
s = tmp;
} else {
s = new Socket(Proxy.NO_PROXY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;

@SuppressWarnings("removal")
public class JPEGImageReader extends ImageReader {

private boolean debug = false;
Expand Down Expand Up @@ -87,6 +86,11 @@ public class JPEGImageReader extends ImageReader {
private int numImages = 0;

static {
initStatic();
}

@SuppressWarnings("removal")
private static void initStatic() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;

@SuppressWarnings("removal")
public class JPEGImageWriter extends ImageWriter {

///////// Private variables
Expand Down Expand Up @@ -173,6 +172,11 @@ public class JPEGImageWriter extends ImageWriter {
///////// static initializer

static {
initStatic();
}

@SuppressWarnings("removal")
private static void initStatic() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
@Override
Expand Down
13 changes: 10 additions & 3 deletions src/java.desktop/share/classes/java/awt/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@
* @author Arthur van Hoff
* @author Sami Shaio
*/
@SuppressWarnings("removal")
public abstract class Component implements ImageObserver, MenuContainer,
Serializable
{
Expand Down Expand Up @@ -506,6 +505,7 @@ static class AWTTreeLock {}
/*
* The component's AccessControlContext.
*/
@SuppressWarnings("removal")
private transient volatile AccessControlContext acc =
AccessController.getContext();

Expand Down Expand Up @@ -627,13 +627,15 @@ static class AWTTreeLock {}
initIDs();
}

@SuppressWarnings("removal")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused. I thought the reason this wasn't done in the JEP implementation PR is because of refactoring
that was needed because of the usage in this static block and you could not apply the annotation here.
Yet it seems you are doing exactly what was supposed to be impossible with no refactoring.
Can you explain ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a tiny refactoring here: a new variable s2 is introduced so the 2nd doPrivileged call on line 636 is now also in a declaration statement (for s2) and therefore annotatable. Without this I cannot add the annotation on line 635.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. But I will quote you
"This happens when a deprecated method is called inside a static block. The annotation can only be added to a declaration and here it must be the whole class"

So the way you explained this before made it sound like any time there was any SM API usage in a static block, the entire class needed to be annotated.

Why has the explanation changed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should have been more precise. An annotation can only be added on a declaration, whether it's a variable, a method, or a class. Static block is not a declaration and the only one covers it is the class. But then if it's on a local variable declaration inside a static block, we certainly can annotate on that variable.

String s = java.security.AccessController.doPrivileged(
new GetPropertyAction("awt.image.incrementaldraw"));
isInc = (s == null || s.equals("true"));

s = java.security.AccessController.doPrivileged(
@SuppressWarnings("removal")
String s2 = java.security.AccessController.doPrivileged(
new GetPropertyAction("awt.image.redrawrate"));
incRate = (s != null) ? Integer.parseInt(s) : 100;
incRate = (s2 != null) ? Integer.parseInt(s2) : 100;
}

/**
Expand Down Expand Up @@ -712,6 +714,7 @@ Object getObjectLock() {
/*
* Returns the acc this component was constructed with.
*/
@SuppressWarnings("removal")
final AccessControlContext getAccessControlContext() {
if (acc == null) {
throw new SecurityException("Component is missing AccessControlContext");
Expand Down Expand Up @@ -974,6 +977,7 @@ public void processEvent(Component comp, AWTEvent e) {
comp.processEvent(e);
}

@SuppressWarnings("removal")
public AccessControlContext getAccessControlContext(Component comp) {
return comp.getAccessControlContext();
}
Expand Down Expand Up @@ -1427,6 +1431,7 @@ public Point getMousePosition() throws HeadlessException {
throw new HeadlessException();
}

@SuppressWarnings("removal")
PointerInfo pi = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<PointerInfo>() {
public PointerInfo run() {
Expand Down Expand Up @@ -6253,6 +6258,7 @@ private boolean checkCoalescing() {
}

// Need to check non-bootstraps.
@SuppressWarnings("removal")
Boolean enabled = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Boolean>() {
public Boolean run() {
Expand Down Expand Up @@ -8988,6 +8994,7 @@ 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
Expand Down
11 changes: 5 additions & 6 deletions src/java.desktop/share/classes/java/awt/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
* @see LayoutManager
* @since 1.0
*/
@SuppressWarnings("removal")
public class Container extends Component {

private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Container");
Expand Down Expand Up @@ -1576,12 +1575,11 @@ public boolean isValidateRoot() {
return false;
}

private static final boolean isJavaAwtSmartInvalidate;
static {
// Don't lazy-read because every app uses invalidate()
isJavaAwtSmartInvalidate = AccessController.doPrivileged(
// Don't lazy-read because every app uses invalidate()
@SuppressWarnings("removal")
private static final boolean isJavaAwtSmartInvalidate
= AccessController.doPrivileged(
new GetBooleanAction("java.awt.smartInvalidate"));
}

/**
* Invalidates the parent of the container unless the container
Expand Down Expand Up @@ -2634,6 +2632,7 @@ public Point getMousePosition(boolean allowChildren) throws HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
@SuppressWarnings("removal")
PointerInfo pi = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<PointerInfo>() {
public PointerInfo run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
* @see Component#getFocusTraversalKeys
* @since 1.4
*/
@SuppressWarnings("removal")
public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.DefaultKeyboardFocusManager");

Expand All @@ -84,6 +83,11 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
private static boolean fxAppThreadIsDispatchThread;

static {
initStatic();
}

@SuppressWarnings("removal")
private static void initStatic() {
AWTAccessor.setDefaultKeyboardFocusManagerAccessor(
new AWTAccessor.DefaultKeyboardFocusManagerAccessor() {
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e) {
Expand Down
Loading