Skip to content

Commit 4087ffb

Browse files
idodeclareVladimir Kotal
authored andcommitted
Retry on ctags tagLine == null. Adjust ctags logging.
1 parent ebb754a commit 4087ffb

File tree

1 file changed

+22
-10
lines changed
  • opengrok-indexer/src/main/java/org/opengrok/indexer/analysis

1 file changed

+22
-10
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/Ctags.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,20 @@ public Definitions doCtags(String file) throws IOException,
392392
*
393393
* @param bufferTags tags file output
394394
* @return definitions parsed from buffer
395+
* @throws java.lang.InterruptedException
395396
*/
396-
public Definitions testCtagsParser(String bufferTags) {
397+
public Definitions testCtagsParser(String bufferTags)
398+
throws InterruptedException {
399+
400+
// Ensure output is magic-terminated as expected.
401+
StringBuilder tagsBuilder = new StringBuilder(bufferTags);
402+
if (!bufferTags.endsWith("\n")) {
403+
tagsBuilder.append("\n");
404+
}
405+
tagsBuilder.append(CTAGS_FILTER_TERMINATOR);
406+
tagsBuilder.append("\n");
407+
bufferTags = tagsBuilder.toString();
408+
397409
junit_testing = true;
398410
ctagsOut = new BufferedReader(new StringReader(bufferTags));
399411
ctags = new Process() {
@@ -429,11 +441,7 @@ public void destroy() {
429441

430442
CtagsReader rdr = new CtagsReader();
431443
rdr.setTabSize(tabSize);
432-
try {
433-
readTags(rdr);
434-
} catch (InterruptedException ex) {
435-
LOGGER.log(Level.SEVERE, "readTags() test", ex);
436-
}
444+
readTags(rdr);
437445
Definitions ret = rdr.getDefinitions();
438446
return ret;
439447
}
@@ -449,18 +457,22 @@ private void readTags(CtagsReader reader) throws InterruptedException {
449457
//log.fine("Tagline:-->" + tagLine+"<----ONELINE");
450458
if (tagLine == null) {
451459
if (!junit_testing) {
452-
LOGGER.warning("Unexpected end of file!");
460+
LOGGER.warning("ctags: Unexpected end of file!");
453461
}
454462
try {
455463
int val = ctags.exitValue();
456464
if (!junit_testing) {
457465
LOGGER.log(Level.WARNING, "ctags exited with code: {0}", val);
458466
}
467+
} catch (IllegalThreadStateException e) {
468+
LOGGER.log(Level.WARNING, "ctags EOF but did not exit");
469+
ctags.destroyForcibly();
459470
} catch (Exception e) {
460-
LOGGER.log(Level.WARNING, "Ctags problem: ", e);
471+
LOGGER.log(Level.WARNING, "ctags problem:", e);
472+
ctags.destroyForcibly();
461473
}
462-
LOGGER.fine("Ctag read");
463-
return;
474+
// Throw the following to indicate non-I/O error for retry.
475+
throw new InterruptedException("tagLine == null");
464476
}
465477

466478
if (CTAGS_FILTER_TERMINATOR.equals(tagLine)) {

0 commit comments

Comments
 (0)