Skip to content

Commit 0954923

Browse files
author
Vladimir Kotal
authored
do not throw IllegalStateException in web app (#3779)
* do not throw IllegalStateException in web app * add test
1 parent 311d83f commit 0954923

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/Repository.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ void assignTagsInHistory(History hist) {
319319
}
320320

321321
if (this.getTagList() == null) {
322-
throw new IllegalStateException("getTagList() is null");
322+
if (RuntimeEnvironment.getInstance().isIndexer()) {
323+
throw new IllegalStateException("getTagList() is null");
324+
} else {
325+
return;
326+
}
323327
}
324328

325329
Iterator<TagEntry> it = this.getTagList().descendingIterator();

opengrok-indexer/src/test/java/org/opengrok/indexer/history/HistoryGuruTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2828
import static org.junit.jupiter.api.Assertions.assertNotNull;
2929
import static org.junit.jupiter.api.Assertions.assertNull;
30+
import static org.junit.jupiter.api.Assertions.assertThrows;
3031
import static org.junit.jupiter.api.Assertions.assertTrue;
3132
import static org.opengrok.indexer.condition.RepositoryInstalled.Type.CVS;
3233
import static org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL;
@@ -46,6 +47,8 @@
4647
import org.junit.jupiter.api.AfterEach;
4748
import org.junit.jupiter.api.BeforeAll;
4849
import org.junit.jupiter.api.Test;
50+
import org.junit.jupiter.params.ParameterizedTest;
51+
import org.junit.jupiter.params.provider.ValueSource;
4952
import org.opengrok.indexer.condition.EnabledForRepository;
5053
import org.opengrok.indexer.configuration.RuntimeEnvironment;
5154
import org.opengrok.indexer.util.FileUtilities;
@@ -282,9 +285,28 @@ public void testScanningDepth() throws IOException {
282285
}
283286

284287
@Test
285-
void testGetLastHistoryEntry() throws HistoryException {
288+
void testGetLastHistoryEntryNonexistent() throws HistoryException {
286289
HistoryGuru instance = HistoryGuru.getInstance();
287290
File file = new File("/nonexistent");
288291
assertNull(instance.getLastHistoryEntry(file, true));
289292
}
293+
294+
@ParameterizedTest
295+
@ValueSource(booleans = {true, false})
296+
void testGetLastHistoryEntry(boolean isIndexerParam) throws HistoryException {
297+
boolean isIndexer = env.isIndexer();
298+
env.setIndexer(isIndexerParam);
299+
boolean isTagsEnabled = env.isTagsEnabled();
300+
env.setTagsEnabled(true);
301+
HistoryGuru instance = HistoryGuru.getInstance();
302+
File file = new File(repository.getSourceRoot(), "git");
303+
assertTrue(file.exists());
304+
if (isIndexerParam) {
305+
assertThrows(IllegalStateException.class, () -> instance.getLastHistoryEntry(file, true));
306+
} else {
307+
assertNotNull(instance.getLastHistoryEntry(file, true));
308+
}
309+
env.setIndexer(isIndexer);
310+
env.setTagsEnabled(isTagsEnabled);
311+
}
290312
}

0 commit comments

Comments
 (0)