8210692: The "com.sun.awt.SecurityWarning" class can be dropped
authorserb
Sat, 22 Sep 2018 20:31:45 -0700
changeset 51929 0e514f1549b4
parent 51928 d96a607e9594
child 51930 a642a0efc36d
8210692: The "com.sun.awt.SecurityWarning" class can be dropped Reviewed-by: prr, mullan, mchung
src/java.base/share/lib/security/default.policy
src/java.desktop/share/classes/com/sun/awt/SecurityWarning.java
src/java.desktop/share/classes/java/awt/Window.java
src/java.desktop/share/classes/sun/awt/AWTAccessor.java
test/jdk/TEST.ROOT
test/jdk/TEST.groups
test/jdk/com/sun/awt/SecurityWarning/CustomSecurityManager.java
test/jdk/com/sun/awt/SecurityWarning/GetSizeShouldNotReturnZero.java
test/jdk/com/sun/awt/TEST.properties
test/jdk/java/awt/Mixing/AWT_Mixing/OpaqueOverlappingChoice.java
--- a/src/java.base/share/lib/security/default.policy	Tue Sep 18 18:32:03 2018 -0700
+++ b/src/java.base/share/lib/security/default.policy	Sat Sep 22 20:31:45 2018 -0700
@@ -140,10 +140,6 @@
     permission java.io.FilePermission "<<ALL FILES>>", "read";
 };
 
-grant codeBase "jrt:/jdk.desktop" {
-    permission java.lang.RuntimePermission "accessClassInPackage.com.sun.awt";
-};
-
 grant codeBase "jrt:/jdk.dynalink" {
     permission java.security.AllPermission;
 };
--- a/src/java.desktop/share/classes/com/sun/awt/SecurityWarning.java	Tue Sep 18 18:32:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,172 +0,0 @@
-/*
- * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.awt;
-
-import java.awt.*;
-import java.awt.geom.*;
-
-import sun.awt.AWTAccessor;
-
-
-/**
- * Security Warning control interface.
- *
- * This class provides a couple of methods that help a developer relocate
- * the AWT security warning to an appropriate position relative to the current
- * window size. A "top-level window" is an instance of the {@code Window}
- * class (or its descendant, such as {@code JFrame}). The security warning
- * is applied to all windows created by an untrusted code. All such windows
- * have a non-null "warning string" (see {@link Window#getWarningString()}).
- * <p>
- * <b>WARNING</b>: This class is an implementation detail and only meant
- * for limited use outside of the core platform. This API may change
- * drastically between update release, and it may even be
- * removed or be moved to some other packages or classes.
- *
- * @deprecated This class is deprecated, no replacement.
- */
-@Deprecated(since = "11", forRemoval = true)
-public final class SecurityWarning {
-
-    /**
-     * The SecurityWarning class should not be instantiated
-     */
-    private SecurityWarning() {
-    }
-
-    /**
-     * Gets the size of the security warning.
-     *
-     * The returned value is not valid until the peer has been created. Before
-     * invoking this method a developer must call the {@link Window#pack()},
-     * {@link Window#setVisible}, or some other method that creates the peer.
-     *
-     * @param window the window to get the security warning size for
-     *
-     * @throws NullPointerException if the window argument is null
-     * @throws IllegalArgumentException if the window is trusted (i.e.
-     * the {@code getWarningString()} returns null)
-     */
-    public static Dimension getSize(Window window) {
-        if (window == null) {
-            throw new NullPointerException(
-                    "The window argument should not be null.");
-        }
-        if (window.getWarningString() == null) {
-            throw new IllegalArgumentException(
-                    "The window must have a non-null warning string.");
-        }
-        // We don't check for a non-null peer since it may be destroyed
-        // after assigning a valid value to the security warning size.
-
-        return AWTAccessor.getWindowAccessor().getSecurityWarningSize(window);
-    }
-
-    /**
-     * Sets the position of the security warning.
-     * <p>
-     * The {@code alignmentX} and {@code alignmentY} arguments specify the
-     * origin of the coordinate system used to calculate the position of the
-     * security warning. The values must be in the range [0.0f...1.0f].  The
-     * {@code 0.0f} value represents the left (top) edge of the rectangular
-     * bounds of the window. The {@code 1.0f} value represents the right
-     * (bottom) edge of the bounds. Whenever the size of the window changes,
-     * the origin of the coordinate system gets relocated accordingly. For
-     * convenience a developer may use the {@code Component.*_ALIGNMENT}
-     * constants to pass predefined values for these arguments.
-     * <p>
-     * The {@code point} argument specifies the location of the security
-     * warning in the coordinate system described above. If both {@code x} and
-     * {@code y} coordinates of the point are equal to zero, the warning will
-     * be located right in the origin of the coordinate system. On the other
-     * hand, if both {@code alignmentX} and {@code alignmentY} are equal to
-     * zero (i.e. the origin of the coordinate system is placed at the top-left
-     * corner of the window), then the {@code point} argument represents the
-     * absolute location of the security warning relative to the location of
-     * the window. The "absolute" in this case means that the position of the
-     * security warning is not effected by resizing of the window.
-     * <p>
-     * Note that the security warning management code guarantees that:
-     * <ul>
-     * <li>The security warning cannot be located farther than two pixels from
-     * the rectangular bounds of the window (see {@link Window#getBounds}), and
-     * <li>The security warning is always visible on the screen.
-     * </ul>
-     * If either of the conditions is violated, the calculated position of the
-     * security warning is adjusted by the system to meet both these
-     * conditions.
-     * <p>
-     * The default position of the security warning is in the upper-right
-     * corner of the window, two pixels to the right from the right edge. This
-     * corresponds to the following arguments passed to this method:
-     * <ul>
-     * <li>{@code alignmentX = Component.RIGHT_ALIGNMENT}
-     * <li>{@code alignmentY = Component.TOP_ALIGNMENT}
-     * <li>{@code point = (2, 0)}
-     * </ul>
-     *
-     * @param window the window to set the position of the security warning for
-     * @param alignmentX the horizontal origin of the coordinate system
-     * @param alignmentY the vertical origin of the coordinate system
-     * @param point the position of the security warning in the specified
-     * coordinate system
-     *
-     * @throws NullPointerException if the window argument is null
-     * @throws NullPointerException if the point argument is null
-     * @throws IllegalArgumentException if the window is trusted (i.e.
-     * the {@code getWarningString()} returns null
-     * @throws IllegalArgumentException if the alignmentX or alignmentY
-     * arguments are not within the range [0.0f ... 1.0f]
-     */
-    public static void setPosition(Window window, Point2D point,
-            float alignmentX, float alignmentY)
-    {
-        if (window == null) {
-            throw new NullPointerException(
-                    "The window argument should not be null.");
-        }
-        if (window.getWarningString() == null) {
-            throw new IllegalArgumentException(
-                    "The window must have a non-null warning string.");
-        }
-        if (point == null) {
-            throw new NullPointerException(
-                    "The point argument must not be null");
-        }
-        if (alignmentX < 0.0f || alignmentX > 1.0f) {
-            throw new IllegalArgumentException(
-                    "alignmentX must be in the range [0.0f ... 1.0f].");
-        }
-        if (alignmentY < 0.0f || alignmentY > 1.0f) {
-            throw new IllegalArgumentException(
-                    "alignmentY must be in the range [0.0f ... 1.0f].");
-        }
-
-        AWTAccessor.getWindowAccessor().setSecurityWarningPosition(window,
-                point, alignmentX, alignmentY);
-    }
-}
-
--- a/src/java.desktop/share/classes/java/awt/Window.java	Tue Sep 18 18:32:03 2018 -0700
+++ b/src/java.desktop/share/classes/java/awt/Window.java	Sat Sep 22 20:31:45 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -394,16 +394,6 @@
     private transient volatile int securityWarningWidth = 0;
     private transient volatile int securityWarningHeight = 0;
 
-    /**
-     * These fields represent the desired location for the security
-     * warning if this window is untrusted.
-     * See com.sun.awt.SecurityWarning for more details.
-     */
-    private transient double securityWarningPointX = 2.0;
-    private transient double securityWarningPointY = 0.0;
-    private transient float securityWarningAlignmentX = RIGHT_ALIGNMENT;
-    private transient float securityWarningAlignmentY = TOP_ALIGNMENT;
-
     static {
         /* ensure that the necessary native libraries are loaded */
         Toolkit.loadLibraries();
@@ -3127,10 +3117,6 @@
 
          this.securityWarningWidth = 0;
          this.securityWarningHeight = 0;
-         this.securityWarningPointX = 2.0;
-         this.securityWarningPointY = 0.0;
-         this.securityWarningAlignmentX = RIGHT_ALIGNMENT;
-         this.securityWarningAlignmentY = TOP_ALIGNMENT;
 
          deserializeResources(s);
     }
@@ -4031,9 +4017,9 @@
     private Point2D calculateSecurityWarningPosition(double x, double y,
             double w, double h)
     {
-        // The position according to the spec of SecurityWarning.setPosition()
-        double wx = x + w * securityWarningAlignmentX + securityWarningPointX;
-        double wy = y + h * securityWarningAlignmentY + securityWarningPointY;
+         // The desired location for the security warning
+        double wx = x + w * RIGHT_ALIGNMENT + 2.0;
+        double wy = y + h * TOP_ALIGNMENT + 0.0;
 
         // First, make sure the warning is not too far from the window bounds
         wx = Window.limit(wx,
@@ -4068,33 +4054,12 @@
                 window.updateWindow();
             }
 
-            public Dimension getSecurityWarningSize(Window window) {
-                return new Dimension(window.securityWarningWidth,
-                        window.securityWarningHeight);
-            }
-
             public void setSecurityWarningSize(Window window, int width, int height)
             {
                 window.securityWarningWidth = width;
                 window.securityWarningHeight = height;
             }
 
-            public void setSecurityWarningPosition(Window window,
-                    Point2D point, float alignmentX, float alignmentY)
-            {
-                window.securityWarningPointX = point.getX();
-                window.securityWarningPointY = point.getY();
-                window.securityWarningAlignmentX = alignmentX;
-                window.securityWarningAlignmentY = alignmentY;
-
-                synchronized (window.getTreeLock()) {
-                    WindowPeer peer = (WindowPeer) window.peer;
-                    if (peer != null) {
-                        peer.repositionSecurityWarning();
-                    }
-                }
-            }
-
             public Point2D calculateSecurityWarningPosition(Window window,
                     double x, double y, double w, double h)
             {
--- a/src/java.desktop/share/classes/sun/awt/AWTAccessor.java	Tue Sep 18 18:32:03 2018 -0700
+++ b/src/java.desktop/share/classes/sun/awt/AWTAccessor.java	Sat Sep 22 20:31:45 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -295,20 +295,11 @@
          */
         void updateWindow(Window window);
 
-        /** Get the size of the security warning.
-         */
-        Dimension getSecurityWarningSize(Window w);
-
         /**
          * Set the size of the security warning.
          */
         void setSecurityWarningSize(Window w, int width, int height);
 
-        /** Set the position of the security warning.
-         */
-        void setSecurityWarningPosition(Window w, Point2D point,
-                float alignmentX, float alignmentY);
-
         /** Request to recalculate the new position of the security warning for
          * the given window size/location as reported by the native system.
          */
--- a/test/jdk/TEST.ROOT	Tue Sep 18 18:32:03 2018 -0700
+++ b/test/jdk/TEST.ROOT	Sat Sep 22 20:31:45 2018 -0700
@@ -19,7 +19,7 @@
 # Tests that must run in othervm mode
 othervm.dirs=java/awt java/beans javax/accessibility javax/imageio javax/sound javax/swing javax/print \
 com/apple/laf com/sun/java/accessibility com/sun/java/swing sanity/client demo/jfc \
-javax/management com/sun/awt sun/awt sun/java2d javax/xml/jaxp/testng/validation java/lang/ProcessHandle
+javax/management sun/awt sun/java2d javax/xml/jaxp/testng/validation java/lang/ProcessHandle
 
 # Tests that cannot run concurrently
 exclusiveAccess.dirs=java/rmi/Naming java/util/prefs sun/management/jmxremote sun/tools/jstatd sun/security/mscapi java/util/stream java/util/Arrays/largeMemory java/util/BitSet/stream javax/rmi
--- a/test/jdk/TEST.groups	Tue Sep 18 18:32:03 2018 -0700
+++ b/test/jdk/TEST.groups	Sat Sep 22 20:31:45 2018 -0700
@@ -351,7 +351,6 @@
 
 jdk_awt = \
     java/awt \
-    com/sun/awt \
     com/apple/eawt \
     com/apple/laf \
     sun/awt
@@ -489,8 +488,7 @@
     :jdk_sound \
     :jdk_sctp \
     javax/accessibility \
-    com/sun/java/swing \
-    com/sun/awt
+    com/sun/java/swing
 
 needs_g1gc = \
   jdk/jfr/event/gc/refstat/TestRefStatEventWithG1ConcurrentMark.java \
--- a/test/jdk/com/sun/awt/SecurityWarning/CustomSecurityManager.java	Tue Sep 18 18:32:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import sun.awt.AWTPermissions;
-import java.security.Permission;
-
-public class CustomSecurityManager extends SecurityManager {
-    @Override
-    public void checkPermission(Permission perm) {
-        if (perm.implies(AWTPermissions.TOPLEVEL_WINDOW_PERMISSION)) {
-            throw new SecurityException();
-        }
-    }
-}
--- a/test/jdk/com/sun/awt/SecurityWarning/GetSizeShouldNotReturnZero.java	Tue Sep 18 18:32:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,187 +0,0 @@
-/*
- * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
-  @test %W% %E%
-  @key headful
-  @bug 6818312
-  @summary The size returned by SecurityWarning.getSize() should not be zero
-  @author anthony.petrov@sun.com: area=awt.toplevel
-  @library ../../../../java/awt/regtesthelpers
-  @modules java.desktop/com.sun.awt
-           java.desktop/sun.awt
-  @build Util CustomSecurityManager CopyClassFile
-  @run main CopyClassFile CustomSecurityManager bootcp/
-  @run main/othervm/secure=CustomSecurityManager -Xbootclasspath/a:bootcp GetSizeShouldNotReturnZero
-*/
-
-/**
- * GetSizeShouldNotReturnZero.java
- *
- * summary: The size returned by SecurityWarning.getSize() should not be zero
- */
-
-import com.sun.awt.SecurityWarning;
-import test.java.awt.regtesthelpers.Util;
-
-import java.awt.*;
-
-public class GetSizeShouldNotReturnZero
-{
-    private static void init()
-    {
-        Frame f = new Frame();
-        f.setSize(100, 100);
-        f.setVisible(true);
-
-        Robot robot = Util.createRobot();
-        Util.waitForIdle(robot);
-
-        Dimension size = SecurityWarning.getSize(f);
-        if (size.width == 0 || size.height == 0) {
-            fail("Reported security warning size: " + size);
-            return;
-        }
-        pass();
-    }//End  init()
-
-
-    /*****************************************************
-     * Standard Test Machinery Section
-     * DO NOT modify anything in this section -- it's a
-     * standard chunk of code which has all of the
-     * synchronisation necessary for the test harness.
-     * By keeping it the same in all tests, it is easier
-     * to read and understand someone else's test, as
-     * well as insuring that all tests behave correctly
-     * with the test harness.
-     * There is a section following this for test-
-     * classes
-     ******************************************************/
-    private static boolean theTestPassed = false;
-    private static boolean testGeneratedInterrupt = false;
-    private static String failureMessage = "";
-
-    private static Thread mainThread = null;
-
-    private static int sleepTime = 300000;
-
-    // Not sure about what happens if multiple of this test are
-    //  instantiated in the same VM.  Being static (and using
-    //  static vars), it aint gonna work.  Not worrying about
-    //  it for now.
-    public static void main( String args[] ) throws InterruptedException
-    {
-        mainThread = Thread.currentThread();
-        try
-        {
-            init();
-        }
-        catch( TestPassedException e )
-        {
-            //The test passed, so just return from main and harness will
-            // interepret this return as a pass
-            return;
-        }
-        //At this point, neither test pass nor test fail has been
-        // called -- either would have thrown an exception and ended the
-        // test, so we know we have multiple threads.
-
-        //Test involves other threads, so sleep and wait for them to
-        // called pass() or fail()
-        try
-        {
-            Thread.sleep( sleepTime );
-            //Timed out, so fail the test
-            throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
-        }
-        catch (InterruptedException e)
-        {
-            //The test harness may have interrupted the test.  If so, rethrow the exception
-            // so that the harness gets it and deals with it.
-            if( ! testGeneratedInterrupt ) throw e;
-
-            //reset flag in case hit this code more than once for some reason (just safety)
-            testGeneratedInterrupt = false;
-
-            if ( theTestPassed == false )
-            {
-                throw new RuntimeException( failureMessage );
-            }
-        }
-
-    }//main
-
-    public static synchronized void setTimeoutTo( int seconds )
-    {
-        sleepTime = seconds * 1000;
-    }
-
-    public static synchronized void pass()
-    {
-        System.out.println( "The test passed." );
-        System.out.println( "The test is over, hit  Ctl-C to stop Java VM" );
-        //first check if this is executing in main thread
-        if ( mainThread == Thread.currentThread() )
-        {
-            //Still in the main thread, so set the flag just for kicks,
-            // and throw a test passed exception which will be caught
-            // and end the test.
-            theTestPassed = true;
-            throw new TestPassedException();
-        }
-        theTestPassed = true;
-        testGeneratedInterrupt = true;
-        mainThread.interrupt();
-    }//pass()
-
-    public static synchronized void fail()
-    {
-        //test writer didn't specify why test failed, so give generic
-        fail( "it just plain failed! :-)" );
-    }
-
-    public static synchronized void fail( String whyFailed )
-    {
-        System.out.println( "The test failed: " + whyFailed );
-        System.out.println( "The test is over, hit  Ctl-C to stop Java VM" );
-        //check if this called from main thread
-        if ( mainThread == Thread.currentThread() )
-        {
-            //If main thread, fail now 'cause not sleeping
-            throw new RuntimeException( whyFailed );
-        }
-        theTestPassed = false;
-        testGeneratedInterrupt = true;
-        failureMessage = whyFailed;
-        mainThread.interrupt();
-    }//fail()
-
-}// class GetSizeShouldNotReturnZero
-
-//This exception is used to exit from any level of call nesting
-// when it's determined that the test has passed, and immediately
-// end the test.
-class TestPassedException extends RuntimeException
-{
-}
--- a/test/jdk/com/sun/awt/TEST.properties	Tue Sep 18 18:32:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-modules=java.desktop
-
--- a/test/jdk/java/awt/Mixing/AWT_Mixing/OpaqueOverlappingChoice.java	Tue Sep 18 18:32:03 2018 -0700
+++ b/test/jdk/java/awt/Mixing/AWT_Mixing/OpaqueOverlappingChoice.java	Sat Sep 22 20:31:45 2018 -0700
@@ -33,8 +33,7 @@
  * @bug 6994264
  * @summary Opaque overlapping test for Choice AWT component
  * @library /java/awt/patchlib  ../../regtesthelpers
- * @modules java.desktop/com.sun.awt
- *          java.desktop/java.awt.peer
+ * @modules java.desktop/java.awt.peer
  *          java.desktop/sun.awt
  * @build java.desktop/java.awt.Helper
  * @build Util