src/share/classes/java/awt/AWTKeyStroke.java
Print this page
*** 84,94 ****
* Reads keystroke class from AppContext and if null, puts there the
* AWTKeyStroke class.
* Must be called under locked AWTKeyStro
*/
private static Class<AWTKeyStroke> getAWTKeyStrokeClass() {
! Class<AWTKeyStroke> clazz = (Class)AppContext.getAppContext().get(AWTKeyStroke.class);
if (clazz == null) {
clazz = AWTKeyStroke.class;
AppContext.getAppContext().put(AWTKeyStroke.class, AWTKeyStroke.class);
}
return clazz;
--- 84,95 ----
* Reads keystroke class from AppContext and if null, puts there the
* AWTKeyStroke class.
* Must be called under locked AWTKeyStro
*/
private static Class<AWTKeyStroke> getAWTKeyStrokeClass() {
! @SuppressWarnings("unchecked")
! Class<AWTKeyStroke> clazz = (Class<AWTKeyStroke>)AppContext.getAppContext().get(AWTKeyStroke.class);
if (clazz == null) {
clazz = AWTKeyStroke.class;
AppContext.getAppContext().put(AWTKeyStroke.class, AWTKeyStroke.class);
}
return clazz;
*** 180,200 ****
protected static void registerSubclass(Class<?> subclass) {
if (subclass == null) {
throw new IllegalArgumentException("subclass cannot be null");
}
synchronized (AWTKeyStroke.class) {
Class<AWTKeyStroke> keyStrokeClass = (Class)AppContext.getAppContext().get(AWTKeyStroke.class);
if (keyStrokeClass != null && keyStrokeClass.equals(subclass)){
// Already registered
return;
}
}
if (!AWTKeyStroke.class.isAssignableFrom(subclass)) {
throw new ClassCastException("subclass is not derived from AWTKeyStroke");
}
! Constructor ctor = getCtor(subclass);
String couldNotInstantiate = "subclass could not be instantiated";
if (ctor == null) {
throw new IllegalArgumentException(couldNotInstantiate);
--- 181,202 ----
protected static void registerSubclass(Class<?> subclass) {
if (subclass == null) {
throw new IllegalArgumentException("subclass cannot be null");
}
synchronized (AWTKeyStroke.class) {
+ @SuppressWarnings("unchecked")
Class<AWTKeyStroke> keyStrokeClass = (Class)AppContext.getAppContext().get(AWTKeyStroke.class);
if (keyStrokeClass != null && keyStrokeClass.equals(subclass)){
// Already registered
return;
}
}
if (!AWTKeyStroke.class.isAssignableFrom(subclass)) {
throw new ClassCastException("subclass is not derived from AWTKeyStroke");
}
! Constructor<?> ctor = getCtor(subclass);
String couldNotInstantiate = "subclass could not be instantiated";
if (ctor == null) {
throw new IllegalArgumentException(couldNotInstantiate);
*** 225,240 ****
/* returns noarg Constructor for class with accessible flag. No security
threat as accessible flag is set only for this Constructor object,
not for Class constructor.
*/
! private static Constructor getCtor(final Class clazz)
{
! Constructor ctor = AccessController.doPrivileged(new PrivilegedAction<Constructor>() {
! public Constructor run() {
try {
! Constructor ctor = clazz.getDeclaredConstructor((Class[]) null);
if (ctor != null) {
ctor.setAccessible(true);
}
return ctor;
} catch (SecurityException e) {
--- 227,242 ----
/* returns noarg Constructor for class with accessible flag. No security
threat as accessible flag is set only for this Constructor object,
not for Class constructor.
*/
! private static Constructor<?> getCtor(final Class<?> clazz)
{
! Constructor<?> ctor = AccessController.doPrivileged(new PrivilegedAction<Constructor<?>>() {
! public Constructor<?> run() {
try {
! Constructor<?> ctor = clazz.getDeclaredConstructor((Class<?>[]) null);
if (ctor != null) {
ctor.setAccessible(true);
}
return ctor;
} catch (SecurityException e) {
*** 247,257 ****
--- 249,261 ----
}
private static synchronized AWTKeyStroke getCachedStroke
(char keyChar, int keyCode, int modifiers, boolean onKeyRelease)
{
+ @SuppressWarnings("unchecked")
Map<AWTKeyStroke, AWTKeyStroke> cache = (Map)AppContext.getAppContext().get(APP_CONTEXT_CACHE_KEY);
+ @SuppressWarnings("unchecked")
AWTKeyStroke cacheKey = (AWTKeyStroke)AppContext.getAppContext().get(APP_CONTEXT_KEYSTROKE_KEY);
if (cache == null) {
cache = new HashMap<>();
AppContext.getAppContext().put(APP_CONTEXT_CACHE_KEY, cache);