8163362: Reconsider reflection usage in java.awt.font.JavaAWTFontAccessImpl class
Reviewed-by: naoto, okutsu, prr
--- a/jdk/src/java.desktop/share/classes/java/awt/font/JavaAWTFontAccessImpl.java Tue Aug 23 10:27:47 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/font/JavaAWTFontAccessImpl.java Tue Aug 23 15:35:44 2016 +0900
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016 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
@@ -25,7 +25,6 @@
package java.awt.font;
-import java.lang.reflect.Field;
import jdk.internal.misc.JavaAWTFontAccess;
class JavaAWTFontAccessImpl implements JavaAWTFontAccess {
@@ -33,19 +32,17 @@
// java.awt.font.TextAttribute constants
public Object getTextAttributeConstant(String name) {
switch (name) {
- case "RUN_DIRECTION":
- case "NUMERIC_SHAPING":
- case "BIDI_EMBEDDING":
- case "RUN_DIRECTION_LTR":
- try {
- Field f = TextAttribute.class.getField(name);
- return f.get(null);
- } catch (NoSuchFieldException | IllegalAccessException x) {
- throw new AssertionError(x);
- }
+ case "RUN_DIRECTION":
+ return TextAttribute.RUN_DIRECTION;
+ case "NUMERIC_SHAPING":
+ return TextAttribute.NUMERIC_SHAPING;
+ case "BIDI_EMBEDDING":
+ return TextAttribute.BIDI_EMBEDDING;
+ case "RUN_DIRECTION_LTR":
+ return TextAttribute.RUN_DIRECTION_LTR;
+ default:
+ throw new AssertionError("Constant name is not recognized");
}
-
- throw new AssertionError("Constant name is not recognized");
}
// java.awt.font.NumericShaper