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/04 02:17:58 UTC

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

mocobeta 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_r280965911
 
 

 ##########
 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:
   Thanks for the comment,
   I noticed another method `Class#getDeclaredField(String)` which does not traverse superclasses.
   https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html#getDeclaredField(java.lang.String)
   Should we use this instead of `getField(String)` ?

----------------------------------------------------------------
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