dsmiley commented on a change in pull request #1109: More pervasive use of PackageLoader / PluginInfo URL: https://github.com/apache/lucene-solr/pull/1109#discussion_r361062854
########## File path: solr/core/src/java/org/apache/solr/core/SolrCore.java ########## @@ -810,28 +809,30 @@ void initIndex(boolean passOnPreviousState, boolean reload) throws IOException { * Creates an instance by trying a constructor that accepts a SolrCore before * trying the default (no arg) constructor. * - * @param className the instance class to create + * @param pluginInfo the instance class to create * @param cast the class or interface that the instance should extend or implement - * @param msg a message helping compose the exception error if any occurs. * @param core The SolrCore instance for which this object needs to be loaded * @return the desired instance * @throws SolrException if the object could not be instantiated */ - public static <T> T createInstance(String className, Class<T> cast, String msg, SolrCore core, ResourceLoader resourceLoader) { - Class<? extends T> clazz = null; - if (msg == null) msg = "SolrCore Object"; + public static <T> T newInstance(PluginInfo pluginInfo, Class<T> cast, SolrCore core, SolrResourceLoader resourceLoader) { + String msg = pluginInfo.type; try { - clazz = resourceLoader.findClass(className, cast); - //most of the classes do not have constructors which takes SolrCore argument. It is recommended to obtain SolrCore by implementing SolrCoreAware. - // So invariably always it will cause a NoSuchMethodException. So iterate though the list of available constructors - Constructor<?>[] cons = clazz.getConstructors(); - for (Constructor<?> con : cons) { - Class<?>[] types = con.getParameterTypes(); - if (types.length == 1 && types[0] == SolrCore.class) { - return cast.cast(con.newInstance(core)); + //TODO separate out "core" scenario to another method + if (pluginInfo.pkgName == null && core != null) { + Class<? extends T> clazz = resourceLoader.findClass(pluginInfo.className, cast); + //most of the classes do not have constructors which takes SolrCore argument. It is recommended to obtain SolrCore by implementing SolrCoreAware. Review comment: I changed this method on SolrCore (formerly createInstance, now newInstance) to take a PluginInfo. This is important because the caller often has one, and the PluginInfo has both the package and class name separated out. Previously, this method only took a String className but that value tended to be pluginInfo.className from the caller which thus stripped out the important information of which package it's on. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org