This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-indexer.git
The following commit(s) were added to refs/heads/master by this push:
new 906057b [MINDEXER-250] BasicUsageExample: ArtifactInfo may be null
(#393)
906057b is described below
commit 906057bd641ce5f215193393a1f8d7fa2a3eed4c
Author: sify21 <[email protected]>
AuthorDate: Thu May 29 20:19:24 2025 +0800
[MINDEXER-250] BasicUsageExample: ArtifactInfo may be null (#393)
`IndexUtils.constructArtifactInfo(doc, centralContext)` may return null,
for example deleted artifacts. Also `IndexReader.document(int)` is
deprecated, use `.storedFields()` to retrieve document.
Signed-off-by: 司芳源 <[email protected]>
---
https://issues.apache.org/jira/browse/MINDEXER-250
---
.../org/apache/maven/index/examples/BasicUsageExample.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git
a/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/index/examples/BasicUsageExample.java
b/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/index/examples/BasicUsageExample.java
index 4b0ef34..eb5f437 100644
---
a/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/index/examples/BasicUsageExample.java
+++
b/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/index/examples/BasicUsageExample.java
@@ -42,6 +42,7 @@ import java.util.Map;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiBits;
+import org.apache.lucene.index.StoredFields;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
@@ -162,13 +163,16 @@ public class BasicUsageExample {
final IndexSearcher searcher =
centralContext.acquireIndexSearcher();
try {
final IndexReader ir = searcher.getIndexReader();
+ final StoredFields storedFields = ir.storedFields();
Bits liveDocs = MultiBits.getLiveDocs(ir);
for (int i = 0; i < ir.maxDoc(); i++) {
if (liveDocs == null || liveDocs.get(i)) {
- final Document doc = ir.document(i);
+ final Document doc = storedFields.document(i);
final ArtifactInfo ai =
IndexUtils.constructArtifactInfo(doc, centralContext);
- System.out.println(ai.getGroupId() + ":" +
ai.getArtifactId() + ":" + ai.getVersion() + ":"
- + ai.getClassifier() + " (sha1=" +
ai.getSha1() + ")");
+ if (ai != null) {
+ System.out.println(ai.getGroupId() + ":" +
ai.getArtifactId() + ":" + ai.getVersion() + ":"
+ + ai.getClassifier() + " (sha1=" +
ai.getSha1() + ")");
+ }
}
}
} finally {