@@ -111,6 +111,8 @@ public class IndexDatabase {
111
111
private static final Comparator <File > FILENAME_COMPARATOR =
112
112
(File p1 , File p2 ) -> p1 .getName ().compareTo (p2 .getName ());
113
113
114
+ private final Object INSTANCE_LOCK = new Object ();
115
+
114
116
private Project project ;
115
117
private FSDirectory indexDirectory ;
116
118
private IndexWriter writer ;
@@ -272,7 +274,7 @@ public void run() {
272
274
273
275
@ SuppressWarnings ("PMD.CollapsibleIfStatements" )
274
276
private void initialize () throws IOException {
275
- synchronized (this ) {
277
+ synchronized (INSTANCE_LOCK ) {
276
278
RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
277
279
File indexDir = new File (env .getDataRootFile (), INDEX_DIR );
278
280
if (project != null ) {
@@ -1151,8 +1153,8 @@ public static Set<String> getAllFiles(List<String> subFiles) throws IOException
1151
1153
*/
1152
1154
public Set <String > getFiles () throws IOException {
1153
1155
IndexReader ireader = null ;
1154
- TermsEnum iter ;
1155
- Terms terms = null ;
1156
+ TermsEnum iter = null ;
1157
+ Terms terms ;
1156
1158
Set <String > files = new HashSet <>();
1157
1159
1158
1160
try {
@@ -1161,8 +1163,8 @@ public Set<String> getFiles() throws IOException {
1161
1163
if (numDocs > 0 ) {
1162
1164
Fields uFields = MultiFields .getFields (ireader );//reader.getTermVectors(0);
1163
1165
terms = uFields .terms (QueryBuilder .U );
1166
+ iter = terms .iterator (); // init uid iterator
1164
1167
}
1165
- iter = terms .iterator (); // init uid iterator
1166
1168
while (iter != null && iter .term () != null ) {
1167
1169
files .add (Util .uid2url (iter .term ().utf8ToString ()));
1168
1170
BytesRef next = iter .next ();
@@ -1241,27 +1243,24 @@ static void listFrequentTokens(List<String> subFiles) throws IOException {
1241
1243
1242
1244
public void listTokens (int freq ) throws IOException {
1243
1245
IndexReader ireader = null ;
1244
- TermsEnum iter ;
1245
- Terms terms = null ;
1246
+ TermsEnum iter = null ;
1247
+ Terms terms ;
1246
1248
1247
1249
try {
1248
1250
ireader = DirectoryReader .open (indexDirectory );
1249
1251
int numDocs = ireader .numDocs ();
1250
1252
if (numDocs > 0 ) {
1251
1253
Fields uFields = MultiFields .getFields (ireader );//reader.getTermVectors(0);
1252
1254
terms = uFields .terms (QueryBuilder .DEFS );
1255
+ iter = terms .iterator (); // init uid iterator
1253
1256
}
1254
- iter = terms .iterator (); // init uid iterator
1255
1257
while (iter != null && iter .term () != null ) {
1256
1258
//if (iter.term().field().startsWith("f")) {
1257
1259
if (iter .docFreq () > 16 && iter .term ().utf8ToString ().length () > freq ) {
1258
1260
LOGGER .warning (iter .term ().utf8ToString ());
1259
1261
}
1260
1262
BytesRef next = iter .next ();
1261
1263
if (next ==null ) {iter =null ;}
1262
- /*} else {
1263
- break;
1264
- }*/
1265
1264
}
1266
1265
} finally {
1267
1266
0 commit comments