mirror of https://github.com/apache/lucene.git
LUCENE-6795: remove unnecessary reflection, everything in question is public
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1702149 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e18e9ba178
commit
0f799cdf59
|
@ -19,8 +19,6 @@ package org.apache.lucene.queryparser.flexible.messages;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -125,27 +123,22 @@ public class NLS {
|
||||||
private static void load(Class<? extends NLS> clazz) {
|
private static void load(Class<? extends NLS> clazz) {
|
||||||
final Field[] fieldArray = clazz.getDeclaredFields();
|
final Field[] fieldArray = clazz.getDeclaredFields();
|
||||||
|
|
||||||
boolean isFieldAccessible = (clazz.getModifiers() & Modifier.PUBLIC) != 0;
|
|
||||||
|
|
||||||
// build a map of field names to Field objects
|
// build a map of field names to Field objects
|
||||||
final int len = fieldArray.length;
|
final int len = fieldArray.length;
|
||||||
Map<String, Field> fields = new HashMap<>(len * 2);
|
Map<String, Field> fields = new HashMap<>(len * 2);
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
fields.put(fieldArray[i].getName(), fieldArray[i]);
|
fields.put(fieldArray[i].getName(), fieldArray[i]);
|
||||||
loadfieldValue(fieldArray[i], isFieldAccessible, clazz);
|
loadfieldValue(fieldArray[i], clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadfieldValue(Field field, boolean isFieldAccessible,
|
private static void loadfieldValue(Field field, Class<? extends NLS> clazz) {
|
||||||
Class<? extends NLS> clazz) {
|
|
||||||
int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC;
|
int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC;
|
||||||
int MOD_MASK = MOD_EXPECTED | Modifier.FINAL;
|
int MOD_MASK = MOD_EXPECTED | Modifier.FINAL;
|
||||||
if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED)
|
if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Set a value for this empty field.
|
// Set a value for this empty field.
|
||||||
if (!isFieldAccessible)
|
|
||||||
makeAccessible(field);
|
|
||||||
try {
|
try {
|
||||||
field.set(null, field.getName());
|
field.set(null, field.getName());
|
||||||
validateMessage(field.getName(), clazz);
|
validateMessage(field.getName(), clazz);
|
||||||
|
@ -178,21 +171,4 @@ public class NLS {
|
||||||
// system
|
// system
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Make a class field accessible
|
|
||||||
*/
|
|
||||||
private static void makeAccessible(final Field field) {
|
|
||||||
if (System.getSecurityManager() == null) {
|
|
||||||
field.setAccessible(true);
|
|
||||||
} else {
|
|
||||||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
|
||||||
@Override
|
|
||||||
public Void run() {
|
|
||||||
field.setAccessible(true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,6 @@ grant {
|
||||||
permission java.lang.RuntimePermission "getStackTrace";
|
permission java.lang.RuntimePermission "getStackTrace";
|
||||||
// needed for mock filesystems in tests
|
// needed for mock filesystems in tests
|
||||||
permission java.lang.RuntimePermission "fileSystemProvider";
|
permission java.lang.RuntimePermission "fileSystemProvider";
|
||||||
// needed by queryparser/ NLS., TODO clean this up:
|
|
||||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.util";
|
|
||||||
// needed for test of IOUtils.spins (maybe it can be avoided)
|
// needed for test of IOUtils.spins (maybe it can be avoided)
|
||||||
permission java.lang.RuntimePermission "getFileStoreAttributes";
|
permission java.lang.RuntimePermission "getFileStoreAttributes";
|
||||||
// analyzers/uima: needed by UIMA message localization... (?)
|
// analyzers/uima: needed by UIMA message localization... (?)
|
||||||
|
|
Loading…
Reference in New Issue