Skip to content

Commit 00e4c74

Browse files
author
Vladimir Kotal
committed
wrap the IOException from writeXref()
1 parent e92cec6 commit 00e4c74

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/plain/PlainAnalyzer.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import java.util.concurrent.ExecutionException;
3232
import java.util.concurrent.TimeUnit;
3333
import java.util.function.Supplier;
34-
import java.util.logging.Level;
35-
import java.util.logging.Logger;
3634

3735
import org.apache.lucene.document.Document;
3836
import org.apache.lucene.document.StoredField;
@@ -50,7 +48,6 @@
5048
import org.opengrok.indexer.analysis.WriteXrefArgs;
5149
import org.opengrok.indexer.analysis.Xrefer;
5250
import org.opengrok.indexer.configuration.RuntimeEnvironment;
53-
import org.opengrok.indexer.logger.LoggerFactory;
5451
import org.opengrok.indexer.search.QueryBuilder;
5552
import org.opengrok.indexer.util.NullWriter;
5653

@@ -62,8 +59,6 @@
6259
*/
6360
public class PlainAnalyzer extends TextAnalyzer {
6461

65-
private static final Logger LOGGER = LoggerFactory.getLogger(PlainAnalyzer.class);
66-
6762
/**
6863
* Creates a new instance of PlainAnalyzer.
6964
* @param factory defined instance for the analyzer
@@ -116,6 +111,19 @@ protected Reader getReader(InputStream stream) throws IOException {
116111
return ExpandTabsReader.wrap(super.getReader(stream), project);
117112
}
118113

114+
private static class XrefWork {
115+
Xrefer xrefer;
116+
Exception exception;
117+
118+
XrefWork(Xrefer xrefer) {
119+
this.xrefer = xrefer;
120+
}
121+
122+
XrefWork(Exception e) {
123+
this.exception = e;
124+
}
125+
}
126+
119127
@Override
120128
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException {
121129
Definitions defs = null;
@@ -157,16 +165,16 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOExc
157165
WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
158166
args.setDefs(defs);
159167
args.setProject(project);
160-
CompletableFuture<Xrefer> future = CompletableFuture.supplyAsync(() -> {
168+
CompletableFuture<XrefWork> future = CompletableFuture.supplyAsync(() -> {
161169
try {
162-
return writeXref(args);
170+
return new XrefWork(writeXref(args));
163171
} catch (IOException e) {
164-
LOGGER.log(Level.WARNING, "I/O exception when generating xref for " + fullPath, e);
165-
return null;
172+
return new XrefWork(e);
166173
}
167174
}, env.getIndexerParallelizer().getXrefWatcherExecutor()).
168175
orTimeout(env.getXrefTimeout(), TimeUnit.SECONDS);
169-
Xrefer xref = future.get(); // Will throw ExecutionException wrapping TimeoutException on timeout.
176+
XrefWork xrefWork = future.get(); // Will throw ExecutionException wrapping TimeoutException on timeout.
177+
Xrefer xref = xrefWork.xrefer;
170178

171179
if (xref != null) {
172180
Scopes scopes = xref.getScopes();
@@ -179,8 +187,8 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOExc
179187
String path = doc.get(QueryBuilder.PATH);
180188
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
181189
} else {
182-
// Re-throw the exception from writeXref(). We no longer have the original exception, though.
183-
throw new IOException("I/O exception when generating xref for " + fullPath);
190+
// Re-throw the exception from writeXref().
191+
throw new IOException(xrefWork.exception);
184192
}
185193
} catch (ExecutionException e) {
186194
throw new InterruptedException("failed to generate xref :" + e);

0 commit comments

Comments
 (0)