You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by GitBox <gi...@apache.org> on 2019/05/03 12:14:06 UTC

[GitHub] [lucene-solr] uschindler commented on a change in pull request #654: LUCENE-8778: Define analyzer SPI names as static final fields and document the names

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_r279932630
 
 

 ##########
 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) &&
+            field.getType().equals(String.class)) {
+          name = ((String)field.get(null)).toLowerCase(Locale.ROOT);
         }
+      } catch (Throwable e) {
 
 Review comment:
   Please catch only real Exceptions, in this case ReflectiveOperationException.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org