On Wed, 19 May 2021 18:38:39 GMT, Weijun Wang <[email protected]> wrote:
>> src/java.desktop/share/classes/java/awt/Component.java line 217:
>>
>>> 215: * @author Sami Shaio
>>> 216: */
>>> 217: @SuppressWarnings("removal")
>>
>> Why is this placed on the *entire class* ??
>> This class is 10535 lines long and mentions AccessControl something like 8
>> places it uses AccessController or AcessControlContext.
>
> 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. The call in this file is
>
> s = java.security.AccessController.doPrivileged(
> new
> GetPropertyAction("awt.image.redrawrate"));
That's a sad limitation of the annotation stuff then, but I don't think that it
is insurmountable.
You can define a static private method to contain this and call it from the
static initializer block.
Much better than applying the annotation to an entire class.
--- a/src/java.desktop/share/classes/java/awt/Component.java
+++ b/src/java.desktop/share/classes/java/awt/Component.java
@@ -618,6 +618,17 @@ public abstract class Component implements ImageObserver,
MenuContainer,
*/
static boolean isInc;
static int incRate;
+
+ private static void initIncRate() {
+ String s = java.security.AccessController.doPrivileged(
+ new
GetPropertyAction("awt.image.incrementaldraw"));
+ isInc = (s == null || s.equals("true"));
+
+ s = java.security.AccessController.doPrivileged(
+ new GetPropertyAction("awt.image.redrawrate"));
+ incRate = (s != null) ? Integer.parseInt(s) : 100;
+ }
+
static {
/* ensure that the necessary native libraries are loaded */
Toolkit.loadLibraries();
@@ -625,14 +636,7 @@ public abstract class Component implements ImageObserver,
MenuContainer,
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
-
- String s = java.security.AccessController.doPrivileged(
- new
GetPropertyAction("awt.image.incrementaldraw"));
- isInc = (s == null || s.equals("true"));
-
- s = java.security.AccessController.doPrivileged(
- new
GetPropertyAction("awt.image.redrawrate"));
- incRate = (s != null) ? Integer.parseInt(s) : 100;
+ initIncRate();
}
-------------
PR: https://git.openjdk.java.net/jdk/pull/4073