Skip to content

Commit 3a99504

Browse files
committed
Use a private instance lock. Fix up some other syntax.
1 parent a57216d commit 3a99504

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/org/opensolaris/opengrok/analysis/AnalyzerGuru.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ public void populateDocument(Document doc, File file, String path,
405405
string_ft_stored_nanalyzed_norms));
406406
doc.add(new Field(QueryBuilder.FULLPATH, file.getAbsolutePath(),
407407
string_ft_nstored_nanalyzed_norms));
408-
doc.add(new SortedDocValuesField(QueryBuilder.FULLPATH, new BytesRef(file.getAbsolutePath())));
408+
doc.add(new SortedDocValuesField(QueryBuilder.FULLPATH,
409+
new BytesRef(file.getAbsolutePath())));
409410

410411
if (RuntimeEnvironment.getInstance().isHistoryEnabled()) {
411412
try {
@@ -420,12 +421,12 @@ public void populateDocument(Document doc, File file, String path,
420421
}
421422
doc.add(new Field(QueryBuilder.DATE, date, string_ft_stored_nanalyzed_norms));
422423
doc.add(new SortedDocValuesField(QueryBuilder.DATE, new BytesRef(date)));
423-
if (path != null) {
424-
doc.add(new TextField(QueryBuilder.PATH, path, Store.YES));
425-
Project project = Project.getProject(path);
426-
if (project != null) {
427-
doc.add(new TextField(QueryBuilder.PROJECT, project.getPath(), Store.YES));
428-
}
424+
425+
// `path' is not null, as it was passed to Util.path2uid() above.
426+
doc.add(new TextField(QueryBuilder.PATH, path, Store.YES));
427+
Project project = Project.getProject(path);
428+
if (project != null) {
429+
doc.add(new TextField(QueryBuilder.PROJECT, project.getPath(), Store.YES));
429430
}
430431

431432
if (fa != null) {

src/org/opensolaris/opengrok/index/IndexDatabase.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public class IndexDatabase {
111111
private static final Comparator<File> FILENAME_COMPARATOR =
112112
(File p1, File p2) -> p1.getName().compareTo(p2.getName());
113113

114+
private final Object INSTANCE_LOCK = new Object();
115+
114116
private Project project;
115117
private FSDirectory indexDirectory;
116118
private IndexWriter writer;
@@ -272,7 +274,7 @@ public void run() {
272274

273275
@SuppressWarnings("PMD.CollapsibleIfStatements")
274276
private void initialize() throws IOException {
275-
synchronized (this) {
277+
synchronized (INSTANCE_LOCK) {
276278
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
277279
File indexDir = new File(env.getDataRootFile(), INDEX_DIR);
278280
if (project != null) {
@@ -1151,8 +1153,8 @@ public static Set<String> getAllFiles(List<String> subFiles) throws IOException
11511153
*/
11521154
public Set<String> getFiles() throws IOException {
11531155
IndexReader ireader = null;
1154-
TermsEnum iter;
1155-
Terms terms = null;
1156+
TermsEnum iter = null;
1157+
Terms terms;
11561158
Set<String> files = new HashSet<>();
11571159

11581160
try {
@@ -1161,8 +1163,8 @@ public Set<String> getFiles() throws IOException {
11611163
if (numDocs > 0) {
11621164
Fields uFields = MultiFields.getFields(ireader);//reader.getTermVectors(0);
11631165
terms = uFields.terms(QueryBuilder.U);
1166+
iter = terms.iterator(); // init uid iterator
11641167
}
1165-
iter = terms.iterator(); // init uid iterator
11661168
while (iter != null && iter.term() != null) {
11671169
files.add(Util.uid2url(iter.term().utf8ToString()));
11681170
BytesRef next = iter.next();
@@ -1241,27 +1243,24 @@ static void listFrequentTokens(List<String> subFiles) throws IOException {
12411243

12421244
public void listTokens(int freq) throws IOException {
12431245
IndexReader ireader = null;
1244-
TermsEnum iter;
1245-
Terms terms = null;
1246+
TermsEnum iter = null;
1247+
Terms terms;
12461248

12471249
try {
12481250
ireader = DirectoryReader.open(indexDirectory);
12491251
int numDocs = ireader.numDocs();
12501252
if (numDocs > 0) {
12511253
Fields uFields = MultiFields.getFields(ireader);//reader.getTermVectors(0);
12521254
terms = uFields.terms(QueryBuilder.DEFS);
1255+
iter = terms.iterator(); // init uid iterator
12531256
}
1254-
iter = terms.iterator(); // init uid iterator
12551257
while (iter != null && iter.term() != null) {
12561258
//if (iter.term().field().startsWith("f")) {
12571259
if (iter.docFreq() > 16 && iter.term().utf8ToString().length() > freq) {
12581260
LOGGER.warning(iter.term().utf8ToString());
12591261
}
12601262
BytesRef next = iter.next();
12611263
if (next==null) {iter=null;}
1262-
/*} else {
1263-
break;
1264-
}*/
12651264
}
12661265
} finally {
12671266

0 commit comments

Comments
 (0)