Index: oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProvider.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProvider.java (revision 858070042fd36da65a26c01e964bf4a9985f2f7f) +++ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProvider.java (revision 5e4bf0fe034b2c31de684730a62a837e0966e1f5) @@ -73,7 +73,7 @@ @Override @NotNull public List getQueryIndexes(NodeState nodeState) { - return ImmutableList. of(new AggregateIndex(newLuceneIndex()), newLucenePropertyIndex()); + return ImmutableList.of(new AggregateIndex(newLuceneIndex()), newLucenePropertyIndex()); } protected LuceneIndex newLuceneIndex() { Index: oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java (revision 858070042fd36da65a26c01e964bf4a9985f2f7f) +++ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java (revision 2f43801d0ab22ddcfb4475b65643f70cfbd2a6e8) @@ -32,8 +32,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import javax.management.NotCompliantMBeanException; - import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; @@ -362,8 +360,7 @@ private AsyncIndexesSizeStatsUpdate asyncIndexesSizeStatsUpdate; @Activate - private void activate(BundleContext bundleContext, Map config) - throws NotCompliantMBeanException, IOException { + private void activate(BundleContext bundleContext, Map config) throws IOException { asyncIndexesSizeStatsUpdate = new AsyncIndexesSizeStatsUpdateImpl( PropertiesUtil.toLong(config.get(LUCENE_INDEX_STATS_UPDATE_INTERVAL), LUCENE_INDEX_STATS_UPDATE_INTERVAL_DEFAULT) * 1000); // convert seconds to millis @@ -532,7 +529,7 @@ editorProvider.setIndexingQueue(checkNotNull(documentQueue)); } - Dictionary props = new Hashtable(); + Dictionary props = new Hashtable<>(); props.put("type", TYPE_LUCENE); regs.add(bundleContext.registerService(IndexEditorProvider.class.getName(), editorProvider, props)); oakRegs.add(registerMBean(whiteboard, @@ -590,14 +587,9 @@ private ExecutorService createExecutor() { ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 60L, TimeUnit.SECONDS, - new LinkedBlockingQueue(), new ThreadFactory() { + new LinkedBlockingQueue<>(), new ThreadFactory() { private final AtomicInteger counter = new AtomicInteger(); - private final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread t, Throwable e) { - log.warn("Error occurred in asynchronous processing ", e); - } - }; + private final Thread.UncaughtExceptionHandler handler = (t, e) -> log.warn("Error occurred in asynchronous processing ", e); @Override public Thread newThread(@NotNull Runnable r) { Thread thread = new Thread(r, createName()); @@ -824,7 +816,7 @@ } private void registerLuceneFileSystemStats(LuceneIndexFileSystemStatistics luceneIndexFSStats, long delayInSeconds) { - Map config = ImmutableMap.of( + Map config = ImmutableMap.of( "scheduler.name", LuceneIndexFileSystemStatistics.class.getName() ); oakRegs.add(scheduleWithFixedDelay(whiteboard, luceneIndexFSStats, config, delayInSeconds, false, true)); Index: oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java (revision 858070042fd36da65a26c01e964bf4a9985f2f7f) +++ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java (revision 5e4bf0fe034b2c31de684730a62a837e0966e1f5) @@ -627,7 +627,7 @@ final boolean requireNodeLevelExcerpt = nodeExcerptColumns.size() > 0; int docID = doc.doc; - List names = new LinkedList(); + List names = new LinkedList<>(); for (IndexableField field : searcher.getIndexReader().document(docID).getFields()) { String name = field.name(); @@ -643,9 +643,7 @@ if (names.size() > 0) { int[] maxPassages = new int[names.size()]; - for (int i = 0; i < maxPassages.length; i++) { - maxPassages[i] = 1; - } + Arrays.fill(maxPassages, 1); try { Map stringMap = postingsHighlighter.highlightFields(names.toArray(new String[names.size()]), query, searcher, new int[]{docID}, maxPassages); @@ -693,7 +691,7 @@ } } } catch (InvalidTokenOffsetsException e) { - LOG.error("higlighting failed", e); + LOG.error("highlighting failed", e); } } } @@ -702,9 +700,7 @@ if (requireNodeLevelExcerpt) { String nodeExcerpt = Joiner.on("...").join(columnNameToExcerpts.values()); - nodeExcerptColumns.forEach( nodeExcerptColumnName -> { - columnNameToExcerpts.put(nodeExcerptColumnName, nodeExcerpt); - }); + nodeExcerptColumns.forEach( nodeExcerptColumnName -> columnNameToExcerpts.put(nodeExcerptColumnName, nodeExcerpt)); } columnNameToExcerpts.keySet().retainAll(excerptFields); @@ -806,7 +802,7 @@ if (original == null || original.isEmpty()) { return original; } - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); for(OrderEntry oe : original) { if (!isNativeSort(oe)) { result.add(oe); @@ -852,7 +848,7 @@ */ private static LuceneRequestFacade getLuceneRequest(IndexPlan plan, IndexAugmentorFactory augmentorFactory, IndexReader reader) { FulltextQueryTermsProvider augmentor = getIndexAgumentor(plan, augmentorFactory); - List qs = new ArrayList(); + List qs = new ArrayList<>(); Filter filter = plan.getFilter(); FullTextExpression ft = filter.getFullTextConstraint(); PlanResult planResult = getPlanResult(plan); @@ -898,12 +894,12 @@ } else if (query.startsWith("spellcheck?")) { String spellcheckQueryString = query.replace("spellcheck?", ""); if (reader != null) { - return new LuceneRequestFacade(SpellcheckHelper.getSpellcheckQuery(spellcheckQueryString, reader)); + return new LuceneRequestFacade<>(SpellcheckHelper.getSpellcheckQuery(spellcheckQueryString, reader)); } } else if (query.startsWith("suggest?")) { String suggestQueryString = query.replace("suggest?", ""); if (reader != null) { - return new LuceneRequestFacade(SuggestHelper.getSuggestQuery(suggestQueryString)); + return new LuceneRequestFacade<>(SuggestHelper.getSuggestQuery(suggestQueryString)); } } else { try { @@ -979,7 +975,7 @@ ibq.add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD); } } - return new LuceneRequestFacade(qs.get(0)); + return new LuceneRequestFacade<>(qs.get(0)); } BooleanQuery bq = new BooleanQuery(); for (Query q : qs) { @@ -992,7 +988,7 @@ bq.add(q, MUST); } } - return new LuceneRequestFacade(bq); + return new LuceneRequestFacade<>(bq); } /** @@ -1375,7 +1371,7 @@ final PlanResult pr = getPlanResult(plan); // a reference to the query, so it can be set in the visitor // (a "non-local return") - final AtomicReference result = new AtomicReference(); + final AtomicReference result = new AtomicReference<>(); ft.accept(new FullTextVisitor() { @Override @@ -1540,7 +1536,7 @@ NodeStateUtils.getNode(rootState, pr.indexPath), plan.getPathPrefix(), false); PropertyIndexResult pir = pr.getPropertyIndexResult(); - FluentIterable paths = null; + FluentIterable paths; if (pir != null) { Iterable queryResult = lookup.query(plan.getFilter(), pir.propertyName, pir.pr); paths = FluentIterable.from(queryResult) @@ -1632,7 +1628,7 @@ String facetFieldName = FulltextIndex.parseFacetField(columnName); if (facets != null) { - ImmutableList.Builder res = new ImmutableList.Builder(); + ImmutableList.Builder res = new ImmutableList.Builder<>(); FacetResult topChildren = facets.getTopChildren(numberOfFacets, facetFieldName); if (topChildren != null) { Index: oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAugmentTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAugmentTest.java (revision 858070042fd36da65a26c01e964bf4a9985f2f7f) +++ oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAugmentTest.java (revision 5e4bf0fe034b2c31de684730a62a837e0966e1f5) @@ -68,7 +68,7 @@ private LuceneIndexNode indexNode; @Override - protected void createTestIndexNode() throws Exception { + protected void createTestIndexNode() { setTraversalEnabled(false); } @@ -190,7 +190,7 @@ assertEquals(TestUtil.NT_TEST, document.getName(JcrConstants.JCR_PRIMARYTYPE)); assertEquals(IndexConstants.INDEX_DEFINITIONS_NODE_TYPE, indexDefinition.getName(JcrConstants.JCR_PRIMARYTYPE)); - return Lists.newArrayList(new StringField("barbar", "1", Field.Store.NO)); + return Lists.newArrayList(new StringField("barbar", "1", Field.Store.NO)); } @NotNull Index: oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderServiceTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderServiceTest.java (revision 858070042fd36da65a26c01e964bf4a9985f2f7f) +++ oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderServiceTest.java (revision 5e4bf0fe034b2c31de684730a62a837e0966e1f5) @@ -157,14 +157,14 @@ } @Test - public void typeProperty() throws Exception{ + public void typeProperty() { MockOsgi.activate(service, context.bundleContext(), getDefaultConfig()); ServiceReference sr = context.bundleContext().getServiceReference(IndexEditorProvider.class.getName()); assertEquals(TYPE_LUCENE, sr.getProperty("type")); } @Test - public void disableOpenIndexAsync() throws Exception{ + public void disableOpenIndexAsync() { Map config = getDefaultConfig(); config.put("enableOpenIndexAsync", false); MockOsgi.activate(service, context.bundleContext(), config); @@ -175,7 +175,7 @@ } @Test - public void enableCopyOnWrite() throws Exception{ + public void enableCopyOnWrite() { Map config = getDefaultConfig(); config.put("enableCopyOnWriteSupport", true); MockOsgi.activate(service, context.bundleContext(), config); @@ -236,7 +236,7 @@ } @Test - public void enablePrefetchIndexFiles() throws Exception{ + public void enablePrefetchIndexFiles() { Map config = getDefaultConfig(); config.put("prefetchIndexFiles", true); MockOsgi.activate(service, context.bundleContext(), config); @@ -248,7 +248,7 @@ } @Test - public void debugLogging() throws Exception{ + public void debugLogging() { Map config = getDefaultConfig(); config.put("debug", true); MockOsgi.activate(service, context.bundleContext(), config); @@ -258,7 +258,7 @@ } @Test - public void enableExtractedTextCaching() throws Exception{ + public void enableExtractedTextCaching() { Map config = getDefaultConfig(); config.put("extractedTextCacheSizeInMB", 11); MockOsgi.activate(service, context.bundleContext(), config); @@ -275,7 +275,7 @@ } @Test - public void preExtractedTextProvider() throws Exception{ + public void preExtractedTextProvider() { MockOsgi.activate(service, context.bundleContext(), getDefaultConfig()); LuceneIndexEditorProvider editorProvider = (LuceneIndexEditorProvider) context.getService(IndexEditorProvider.class); @@ -290,7 +290,7 @@ } @Test - public void preExtractedProviderBindBeforeActivate() throws Exception{ + public void preExtractedProviderBindBeforeActivate() { service.bindExtractedTextProvider(mock(PreExtractedTextProvider.class)); MockOsgi.activate(service, context.bundleContext(), getDefaultConfig()); LuceneIndexEditorProvider editorProvider = @@ -299,7 +299,7 @@ } @Test - public void alwaysUsePreExtractedCache() throws Exception{ + public void alwaysUsePreExtractedCache() { Map config = getDefaultConfig(); config.put("alwaysUsePreExtractedCache", "true"); MockOsgi.activate(service, context.bundleContext(), config); @@ -309,7 +309,7 @@ } @Test - public void booleanQuerySize() throws Exception{ + public void booleanQuerySize() { Map config = getDefaultConfig(); config.put("booleanClauseLimit", 4000); MockOsgi.activate(service, context.bundleContext(), config); @@ -318,7 +318,7 @@ } @Test - public void indexDefnStorafe() throws Exception{ + public void indexDefnStorafe() { Map config = getDefaultConfig(); config.put("disableStoredIndexDefinition", true); MockOsgi.activate(service, context.bundleContext(), config); @@ -355,20 +355,14 @@ final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); - Callable cb1 = new Callable() { - @Override - public Object call() throws Exception { - latch1.await(); - return null; - } + Callable cb1 = () -> { + latch1.await(); + return null; }; - Callable cb2 = new Callable() { - @Override - public Object call() throws Exception { - latch2.countDown(); - return null; - } + Callable cb2 = () -> { + latch2.countDown(); + return null; }; executor.submit(cb1); @@ -383,7 +377,7 @@ @Test - public void singleBlobPerIndexFileConfig() throws Exception { + public void singleBlobPerIndexFileConfig() { Map config = getDefaultConfig(); config.put("enableSingleBlobIndexFiles", "true"); MockOsgi.activate(service, context.bundleContext(), config); @@ -432,7 +426,7 @@ } private Map getDefaultConfig(){ - Map config = new HashMap(); + Map config = new HashMap<>(); config.put("localIndexDir", folder.getRoot().getAbsolutePath()); return config; } Index: oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java (revision 858070042fd36da65a26c01e964bf4a9985f2f7f) +++ oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java (revision 5e4bf0fe034b2c31de684730a62a837e0966e1f5) @@ -95,7 +95,6 @@ import org.apache.jackrabbit.oak.spi.commit.EditorHook; import org.apache.jackrabbit.oak.spi.commit.EmptyHook; import org.apache.jackrabbit.oak.spi.commit.Observable; -import org.apache.jackrabbit.oak.spi.commit.Observer; import org.apache.jackrabbit.oak.spi.query.Cursor; import org.apache.jackrabbit.oak.spi.query.Filter; import org.apache.jackrabbit.oak.spi.query.IndexRow; @@ -119,7 +118,6 @@ import org.junit.Assert; import org.junit.Test; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; @@ -225,12 +223,8 @@ List plans = queryIndex.getPlans(filter, null, indexed); Cursor cursor = queryIndex.query(plans.get(0), indexed); - List paths = copyOf(transform(cursor, new Function() { - public String apply(IndexRow input) { - return input.getPath(); - } - })); - assertTrue(!paths.isEmpty()); + List paths = copyOf(transform(cursor, IndexRow::getPath)); + assertFalse(paths.isEmpty()); assertEquals(LuceneIndex.LUCENE_QUERY_BATCH_SIZE + 1, paths.size()); } @@ -365,7 +359,7 @@ Set uniquePaths = Sets.newHashSet(resultPaths); assertEquals(resultPaths.size(), uniquePaths.size()); - assertTrue(!uniquePaths.isEmpty()); + assertFalse(uniquePaths.isEmpty()); } private void purgeDeletedDocs(NodeBuilder idx, LuceneIndexDefinition definition) throws IOException { @@ -487,7 +481,7 @@ filter = createFilter(NT_TEST); filter.restrictProperty("jcr:content/bar", Operator.EQUAL, null); - assertFilter(filter, queryIndex, indexed, Collections.emptyList()); + assertFilter(filter, queryIndex, indexed, Collections.emptyList()); } @Test @@ -588,7 +582,7 @@ //No stop word configured so default analyzer would also check for 'was' filter.setFullTextConstraint(new FullTextTerm(null, "fox was jumping", false, false, null)); - assertFilter(filter, queryIndex, indexed, Collections.emptyList()); + assertFilter(filter, queryIndex, indexed, Collections.emptyList()); //Change the default analyzer to use the default stopword set //and trigger a reindex such that new analyzer is used @@ -645,12 +639,7 @@ //entering NodeStore nodeStore = SegmentNodeStoreBuilders.builder(new MemoryStore()).build(); tracker = new IndexTracker(); - ((Observable)nodeStore).addObserver(new Observer() { - @Override - public void contentChanged(@NotNull NodeState root, @NotNull CommitInfo info) { - tracker.update(root); - } - }); + ((Observable)nodeStore).addObserver((root, info) -> tracker.update(root)); builder = nodeStore.getRoot().builder(); //Also initialize the NodeType registry required for Lucene index to work @@ -813,7 +802,7 @@ NodeBuilder dir = builder.child("oak:index").child("lucene").child(":data"); //Mutate the blob to fail on access i.e. create corrupt index - List blobs = new ArrayList(); + List blobs = new ArrayList<>(); Blob b = dir.child("segments_1").getProperty(JCR_DATA).getValue(Type.BINARY, 0); FailingBlob fb = new FailingBlob(IOUtils.toByteArray(b.getNewStream())); blobs.add(fb); @@ -846,8 +835,8 @@ } /** - * Given a lucene index with a config error , it should not block other - * indexes to index content and should log a meaningful Exception . Once + * Given a lucene index with a config error, it should not block other + * indexes to index content and should log a meaningful Exception. Once * fixed and reindexed - it should reindex content as expected. */ @Test @@ -889,8 +878,8 @@ PropertyValues.newString("bar")); List plans = queryIndex.getPlans(filter, null, indexed); - // Since the index serving property foo has a config error , no plan should be available - assertTrue(plans.size() == 0); + // Since the index serving property foo has a config error, no plan should be available + assertEquals(0, plans.size()); // Now we check the config error in index1 should not impact the query results and content getting indexed for index 2 FilterImpl filter2 = createFilter(NT_BASE); @@ -915,7 +904,7 @@ indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY); tracker.update(indexed); // Since the config error is now fixed - there should not be any more errors here - assertTrue(customLogs.getLogs().size() == 0); + assertEquals(0, customLogs.getLogs().size()); } finally { customLogs.finished(); } @@ -979,26 +968,6 @@ expected + "\nActual: " + paths, expected.size(), paths.size()); return paths; } - - private static List assertFilter(Filter filter, AdvancedQueryIndex queryIndex, - NodeState indexed, List expected, boolean ordered) { - if (!ordered) { - return assertFilter(filter, queryIndex, indexed, expected); - } - - List plans = queryIndex.getPlans(filter, null, indexed); - Cursor cursor = queryIndex.query(plans.get(0), indexed); - - List paths = newArrayList(); - while (cursor.hasNext()) { - paths.add(cursor.next().getPath()); - } - for (String p : expected) { - assertTrue("Expected path " + p + " not found", paths.contains(p)); - } - assertEquals("Result set size is different", expected.size(), paths.size()); - return paths; - } private String getIndexDir(){ File dir = new File("target", "indexdir"+System.nanoTime());