title: Got NullPointerException when enabled search index for Jackrabbit
body: <p>I'm currently developing application that actively uses jackrabbit. This is my first experience with jackrabbit. I use h2-based configuration for my junit tests. Lucene search was disabled in my repository.xml and the only problem was the following exception in log file:</p>
  
  <pre><code>ERROR org.apache.jackrabbit.core.security.user.MembershipCache  - Failed to retrieve membership references of 21232f29-7a57-35a7-8389-4a0e4a801fc3. 
  javax.jcr.RepositoryException: no search manager configured for this workspace
  </code></pre>
  
  <p>All unit tests passed. When I started to test functionality that uses <a href="http://jackrabbit.apache.org/api/2.2/org/apache/jackrabbit/api/security/user/UserManager.html#findAuthorizables%28org.apache.jackrabbit.api.security.user.Query%29" rel="nofollow">UserManager.findAuthorizables</a> I had to enable SearchIndex in repository.xml.<br>
  Now <strong>all of my tests fail</strong> with frustrating NullPointerException:</p>
  
  <pre><code>java.lang.NullPointerException
      at org.apache.jackrabbit.core.query.lucene.MultiScorer.nextDoc(MultiScorer.java:68)
      at org.apache.lucene.search.ConjunctionScorer.&lt;init&gt;(ConjunctionScorer.java:42)
      at org.apache.lucene.search.ConjunctionScorer.&lt;init&gt;(ConjunctionScorer.java:33)
      at org.apache.lucene.search.BooleanScorer2$2.&lt;init&gt;(BooleanScorer2.java:173)
      at org.apache.lucene.search.BooleanScorer2.countingConjunctionSumScorer(BooleanScorer2.java:173)
      at org.apache.lucene.search.BooleanScorer2.makeCountingSumScorerSomeReq(BooleanScorer2.java:234)
      at org.apache.lucene.search.BooleanScorer2.makeCountingSumScorer(BooleanScorer2.java:211)
      at org.apache.lucene.search.BooleanScorer2.&lt;init&gt;(BooleanScorer2.java:101)
      at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:328)
      at org.apache.jackrabbit.core.query.lucene.ChildAxisQuery$ChildAxisWeight.scorer(ChildAxisQuery.java:334)
      at org.apache.jackrabbit.core.query.lucene.ChildAxisQuery$ChildAxisWeight.scorer(ChildAxisQuery.java:332)
      at org.apache.jackrabbit.core.query.lucene.DescendantSelfAxisQuery$DescendantSelfAxisWeight.scorer(DescendantSelfAxisQuery.java:395)
      at org.apache.jackrabbit.core.query.lucene.LuceneQueryHits.&lt;init&gt;(LuceneQueryHits.java:52)
      at org.apache.jackrabbit.core.query.lucene.JackrabbitIndexSearcher.evaluate(JackrabbitIndexSearcher.java:107)
      at org.apache.jackrabbit.core.query.lucene.JackrabbitIndexSearcher.execute(JackrabbitIndexSearcher.java:85)
      at org.apache.jackrabbit.core.query.lucene.SearchIndex.executeQuery(SearchIndex.java:814)
      at org.apache.jackrabbit.core.query.lucene.SingleColumnQueryResult.executeQuery(SingleColumnQueryResult.java:74)
      at org.apache.jackrabbit.core.query.lucene.QueryResultImpl.getResults(QueryResultImpl.java:275)
      at org.apache.jackrabbit.core.query.lucene.SingleColumnQueryResult.&lt;init&gt;(SingleColumnQueryResult.java:66)
      at org.apache.jackrabbit.core.query.lucene.QueryImpl.execute(QueryImpl.java:134)
      at org.apache.jackrabbit.core.query.QueryImpl$1.perform(QueryImpl.java:132)
      at org.apache.jackrabbit.core.query.QueryImpl$1.perform(QueryImpl.java:129)
      at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
      at org.apache.jackrabbit.core.query.QueryImpl.execute(QueryImpl.java:128)
      at org.apache.jackrabbit.core.security.user.IndexNodeResolver.findNode(IndexNodeResolver.java:73)
      at org.apache.jackrabbit.core.security.user.UserManagerImpl.getAuthorizable(UserManagerImpl.java:465)
      at org.apache.jackrabbit.core.security.user.UserManagerImpl.setPrincipal(UserManagerImpl.java:698)
      at org.apache.jackrabbit.core.security.user.UserManagerImpl.createUser(UserManagerImpl.java:558)
      at org.apache.jackrabbit.core.security.user.UserManagerImpl.createUser(UserManagerImpl.java:541)
      at org.apache.jackrabbit.core.security.user.UserManagerImpl.createAdmin(UserManagerImpl.java:948)
      at org.apache.jackrabbit.core.security.user.UserManagerImpl.getAuthorizable(UserManagerImpl.java:426)
      at org.apache.jackrabbit.core.DefaultSecurityManager.createSystemUsers(DefaultSecurityManager.java:613)
      at org.apache.jackrabbit.core.DefaultSecurityManager.init(DefaultSecurityManager.java:204)
      at org.apache.jackrabbit.core.RepositoryImpl.initSecurityManager(RepositoryImpl.java:463)
      at org.apache.jackrabbit.core.RepositoryImpl.&lt;init&gt;(RepositoryImpl.java:324)
      at org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:582)
      at org.apache.jackrabbit.core.TransientRepository$2.getRepository(TransientRepository.java:232)
      at org.apache.jackrabbit.core.TransientRepository.startRepository(TransientRepository.java:280)
      at org.apache.jackrabbit.core.TransientRepository.login(TransientRepository.java:376)
      at ru.e.e.s.s.BaseJackrabbitRelatedTests.startRepository(BaseJackrabbitRelatedTests.java:81)
      at ru.e.e.s.s.BaseJackrabbitRelatedTests.setUp(BaseJackrabbitRelatedTests.java:64)
      at ru.e.e.s.s.i.p.JackrabbitIdentityRepositoryTests.setUp(JackrabbitIdentityRepositoryTests.java:28)
      ...
  </code></pre>
  
  <p>Here is my repository.xml, which uses default search index configuration:
  </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt; 
  &lt;!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.0//EN" "http://jackrabbit.apache.org/dtd/repository-2.0.dtd"&gt;
  &lt;Repository&gt;
      &lt;FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"&gt;
          &lt;param name="driver" value="org.h2.Driver"/&gt;
          &lt;param name="url" value="jdbc:h2:memFS:test"/&gt;
      &lt;/FileSystem&gt;
      &lt;DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/&gt;
      &lt;Security appName="Jackrabbit"&gt;
          &lt;SecurityManager class="org.apache.jackrabbit.core.DefaultSecurityManager" workspaceName="security"&gt;
              &lt;WorkspaceAccessManager class="org.apache.jackrabbit.core.security.simple.SimpleWorkspaceAccessManager"/&gt; 
          &lt;/SecurityManager&gt;
          &lt;AccessManager class="org.apache.jackrabbit.core.security.DefaultAccessManager" /&gt;
          &lt;LoginModule class="org.apache.jackrabbit.core.security.authentication.DefaultLoginModule"&gt;
              &lt;param name="adminId" value="admin"/&gt;
              &lt;param name="anonimousId" value=""/&gt;
          &lt;/LoginModule&gt;
      &lt;/Security&gt;
      &lt;Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/&gt;
      &lt;Workspace name="${wsp.name}"&gt;
          &lt;FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"&gt;
              &lt;param name="driver" value="org.h2.Driver"/&gt;
              &lt;param name="url" value="jdbc:h2:memFS:testWsp"/&gt;
          &lt;/FileSystem&gt;
          &lt;PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager"&gt;
              &lt;param name="driver" value="org.h2.Driver"/&gt;
              &lt;param name="url" value="jdbc:h2:mem:itemState"/&gt;
          &lt;/PersistenceManager&gt;
          &lt;SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex"&gt;
              &lt;param name="path" value="${wsp.home}/index"/&gt;
              &lt;param name="extractorPoolSize" value="2"/&gt;
          &lt;/SearchIndex&gt;
      &lt;/Workspace&gt;
      &lt;Versioning rootPath="${rep.home}/version"&gt;
          &lt;FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"&gt;
              &lt;param name="driver" value="org.h2.Driver"/&gt;
              &lt;param name="url" value="jdbc:h2:memFS:test/version"/&gt;
          &lt;/FileSystem&gt;
          &lt;PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager"&gt;
              &lt;param name="driver" value="org.h2.Driver"/&gt;
              &lt;param name="url" value="jdbc:h2:mem:version;db_close_delay=10"/&gt;
          &lt;/PersistenceManager&gt;
      &lt;/Versioning&gt;
      &lt;SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex"&gt;
          &lt;param name="path" value="${rep.home}/repository/index"/&gt;
          &lt;param name="extractorPoolSize" value="2"/&gt;
      &lt;/SearchIndex&gt;
  &lt;/Repository&gt;
  </code></pre>
  
  <p>Repository startup code:
  </p>
  
  <pre><code>public abstract class BaseJackrabbitRelatedTests {
      protected static Repository testRepository;
      protected static Credentials adminCredentials;
      private Session keepAliveSession;
  
      @BeforeClass
      public static void setUpBeforeClass() throws Exception {
          cleanRepository();
          testRepository = new TransientRepository(JACKRABBIT_CONFIGURATION_FILE, JACKRABBIT_REPOSITORY_PATH);
          adminCredentials = new SimpleCredentials(JACKRABBIT_USERNAME, JACKRABBIT_PASSWORD.toCharArray());
      }
  
      private static void cleanRepository() throws Exception {
          FileUtils.deleteQuietly(new File(JACKRABBIT_REPOSITORY_PATH));
      }
  
      @Before
      public void setUp() throws Exception {
          startRepository();
          ...
      }
  
      private void startRepository() throws Exception {
          if (keepAliveSession == null) {
              keepAliveSession = testRepository.login(adminCredentials, JACKRABBIT_DEFAULT_WORKSPACE);
          }
      }
      ...
  }
  </code></pre>
  
  <p>I've found this problem on Jackrabbit 2.3.4. I've tried to use recently released 2.4.0 - no success.<br>
  It seems that jackrabbit fails to create users listed in LoginModule configuration section. But why? What am I missing?</p>