uschindler commented on a change in pull request #654: LUCENE-8778: Define
analyzer SPI names as static final fields and document the names
URL: https://github.com/apache/lucene-solr/pull/654#discussion_r280753051
##########
File path:
lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AnalysisSPILoader.java
##########
@@ -83,17 +74,22 @@ public synchronized void reload(ClassLoader classloader) {
final SPIClassIterator<S> loader = SPIClassIterator.get(clazz,
classloader);
while (loader.hasNext()) {
final Class<? extends S> service = loader.next();
- final String clazzName = service.getSimpleName();
String name = null;
- for (String suffix : suffixes) {
- if (clazzName.endsWith(suffix)) {
- name = clazzName.substring(0, clazzName.length() -
suffix.length()).toLowerCase(Locale.ROOT);
- break;
+ Throwable cause = null;
+ try {
+ // Lookup "NAME" field with appropriate modifiers. Also it must be a
String field.
+ final Field field = service.getField("NAME");
+ int modifier = field.getModifiers();
+ if (Modifier.isPublic(modifier) && Modifier.isStatic(modifier) &&
Modifier.isFinal(modifier) &&
Review comment:
Actually, you can leave the check inside to make it more explicit, I just
wanted to mention this:
<https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html#getField(java.lang.String)>:
"Returns a Field object that reflects the specified public member field of the
class or interface represented by this Class object"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]