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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -178,7 +178,6 @@
* @since 1.7
* @author Doug Lea
*/
@SuppressWarnings("removal")
public class ForkJoinPool extends AbstractExecutorService {

/*
@@ -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)
@@ -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<>() {
@@ -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<>() {
@@ -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)
@@ -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);
}
@@ -48,7 +48,6 @@
import sun.util.logging.PlatformLogger;


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

private static int defaultSoTimeout;
@@ -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");
}
Copy link
Member

@dfuch dfuch May 21, 2021

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

@wangweij wangweij May 21, 2021

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) {
@@ -135,7 +131,7 @@ public Object run() {
defaultConnectTimeout = vals[1];
}

encoding = encs[0];
encoding = enc;
try {
if (!isASCIISuperset(encoding)) {
encoding = "ISO8859_1";
@@ -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.
@@ -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);
}
@@ -59,7 +59,6 @@
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;

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

private boolean debug = false;
@@ -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
@@ -63,7 +63,6 @@
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;

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

///////// Private variables
@@ -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
@@ -214,7 +214,6 @@
* @author Arthur van Hoff
* @author Sami Shaio
*/
@SuppressWarnings("removal")
public abstract class Component implements ImageObserver, MenuContainer,
Serializable
{
@@ -506,6 +505,7 @@ static class AWTTreeLock {}
/*
* The component's AccessControlContext.
*/
@SuppressWarnings("removal")
private transient volatile AccessControlContext acc =
AccessController.getContext();

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

@SuppressWarnings("removal")
Copy link
Contributor

@prrace prrace May 27, 2021

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

@wangweij wangweij May 28, 2021

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

@prrace prrace May 28, 2021

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

@wangweij wangweij May 28, 2021

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;
}

/**
@@ -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");
@@ -974,6 +977,7 @@ public void processEvent(Component comp, AWTEvent e) {
comp.processEvent(e);
}

@SuppressWarnings("removal")
public AccessControlContext getAccessControlContext(Component comp) {
return comp.getAccessControlContext();
}
@@ -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() {
@@ -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() {
@@ -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
@@ -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");
@@ -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
@@ -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() {
@@ -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");

@@ -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) {