首页 > 代码库 > solr定时更新索引遇到的问题(SolrDataImportProperties Error loading DataImportScheduler properties java.lang.NullPointerException)

solr定时更新索引遇到的问题(SolrDataImportProperties Error loading DataImportScheduler properties java.lang.NullPointerException)

 问题描述

报如下错误,很显然,问题原因:空指针异常;

ERROR (localhost-startStop-1) [   ] o.a.s.h.d.s.SolrDataImportProperties Error loading DataImportScheduler properties
java.lang.NullPointerException
        at sun.nio.fs.UnixPath.normalizeAndCheck(UnixPath.java:77)
        at sun.nio.fs.UnixPath.<init>(UnixPath.java:71)
        at sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:281)
        at java.nio.file.Paths.get(Paths.java:84)
        at org.apache.solr.core.SolrResourceLoader.<init>(SolrResourceLoader.java:151)
        at org.apache.solr.handler.dataimport.scheduler.SolrDataImportProperties.loadProperties(SolrDataImportProperties.java:36)
        at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.reloadParams(BaseTimerTask.java:57)
        at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.<init>(BaseTimerTask.java:39)
        at org.apache.solr.handler.dataimport.scheduler.DeltaImportHTTPPostScheduler.<init>(DeltaImportHTTPPostScheduler.java:20)
        at org.apache.solr.handler.dataimport.scheduler.ApplicationListener.contextInitialized(ApplicationListener.java:47)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4716)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1107)
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1841)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

详细原因:定时更新使用的jar包apache-solr-dataimportscheduler-1.1.jar是网上找的,好像版本更不上了,反编译一下,问题出在SolrDataImportProperties类的36行,如下标红位置:

    public void loadProperties(boolean force) {        try {            SolrResourceLoader loader = new SolrResourceLoader(null);            logger.info("Instance dir = " + loader.getInstanceDir());            String configDir = loader.getConfigDir();            configDir = SolrResourceLoader.normalizeDir(configDir);

我的solr版本是5.5.3,找到org.apache.solr.core.SolrResourceLoader,查看其构造方法,有四个,我们使用的是public SolrResourceLoader(Path instanceDir),由于传入的instanceDir为null报错(具体内部代码就没调试进去了):

  public SolrResourceLoader() {    this(locateSolrHome(), null, null);  }  public SolrResourceLoader(Path instanceDir, ClassLoader parent)  {    this(instanceDir, parent, null);  }  public SolrResourceLoader(Path instanceDir) {    this(instanceDir, null, null);  }  public SolrResourceLoader(Path instanceDir, ClassLoader parent, Properties coreProperties)  {    if (instanceDir == null) {
  ...

如何解决

修改apache-solr-dataimportscheduler-1.1代码,重新打包,经测试,定时增量更新和全量更新功能正常。

附件(修改后的jar包)

下载链接:

http://files.cnblogs.com/files/chenpi/solr-dataimportscheduler-1.1-source.zip

solr定时更新索引遇到的问题(SolrDataImportProperties Error loading DataImportScheduler properties java.lang.NullPointerException)