lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [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
Date Sat, 04 May 2019 09:10:59 GMT
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_r280975038
 
 

 ##########
 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:
   I have a better idea: Use `getField()` and remove the `isPublic()` check. But do `Objects.equals(field.getDeclaringClass(),
 service)` as safety check. That has no security manager problems and does the check, too.

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


Mime
View raw message