mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-22 00:59:34 +01:00
fixed throws in finally and converted to try with resources
This commit is contained in:
@@ -191,57 +191,35 @@ public final class CpeMemoryIndex {
|
|||||||
* @throws IndexException thrown if there is an issue creating the index
|
* @throws IndexException thrown if there is an issue creating the index
|
||||||
*/
|
*/
|
||||||
private void buildIndex(CveDB cve) throws IndexException {
|
private void buildIndex(CveDB cve) throws IndexException {
|
||||||
Analyzer analyzer = null;
|
try (Analyzer analyzer = createSearchingAnalyzer();
|
||||||
IndexWriter indexWriter = null;
|
IndexWriter indexWriter = new IndexWriter(index, new IndexWriterConfig(LuceneUtils.CURRENT_VERSION, analyzer))) {
|
||||||
try {
|
// Tip: reuse the Document and Fields for performance...
|
||||||
analyzer = createSearchingAnalyzer();
|
// See "Re-use Document and Field instances" from
|
||||||
final IndexWriterConfig conf = new IndexWriterConfig(LuceneUtils.CURRENT_VERSION, analyzer);
|
// http://wiki.apache.org/lucene-java/ImproveIndexingSpeed
|
||||||
indexWriter = new IndexWriter(index, conf);
|
final Document doc = new Document();
|
||||||
try {
|
final Field v = new TextField(Fields.VENDOR, Fields.VENDOR, Field.Store.YES);
|
||||||
// Tip: reuse the Document and Fields for performance...
|
final Field p = new TextField(Fields.PRODUCT, Fields.PRODUCT, Field.Store.YES);
|
||||||
// See "Re-use Document and Field instances" from
|
doc.add(v);
|
||||||
// http://wiki.apache.org/lucene-java/ImproveIndexingSpeed
|
doc.add(p);
|
||||||
final Document doc = new Document();
|
|
||||||
final Field v = new TextField(Fields.VENDOR, Fields.VENDOR, Field.Store.YES);
|
|
||||||
final Field p = new TextField(Fields.PRODUCT, Fields.PRODUCT, Field.Store.YES);
|
|
||||||
doc.add(v);
|
|
||||||
doc.add(p);
|
|
||||||
|
|
||||||
final Set<Pair<String, String>> data = cve.getVendorProductList();
|
final Set<Pair<String, String>> data = cve.getVendorProductList();
|
||||||
for (Pair<String, String> pair : data) {
|
for (Pair<String, String> pair : data) {
|
||||||
//todo figure out why there are null products
|
if (pair.getLeft() != null && pair.getRight() != null) {
|
||||||
if (pair.getLeft() != null && pair.getRight() != null) {
|
v.setStringValue(pair.getLeft());
|
||||||
v.setStringValue(pair.getLeft());
|
p.setStringValue(pair.getRight());
|
||||||
p.setStringValue(pair.getRight());
|
indexWriter.addDocument(doc);
|
||||||
indexWriter.addDocument(doc);
|
resetFieldAnalyzer();
|
||||||
resetFieldAnalyzer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (DatabaseException ex) {
|
|
||||||
LOGGER.debug("", ex);
|
|
||||||
throw new IndexException("Error reading CPE data", ex);
|
|
||||||
}
|
}
|
||||||
|
indexWriter.commit();
|
||||||
|
indexWriter.close(true);
|
||||||
|
} catch (DatabaseException ex) {
|
||||||
|
LOGGER.debug("", ex);
|
||||||
|
throw new IndexException("Error reading CPE data", ex);
|
||||||
} catch (CorruptIndexException ex) {
|
} catch (CorruptIndexException ex) {
|
||||||
throw new IndexException("Unable to close an in-memory index", ex);
|
throw new IndexException("Unable to close an in-memory index", ex);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new IndexException("Unable to close an in-memory index", ex);
|
throw new IndexException("Unable to close an in-memory index", ex);
|
||||||
} finally {
|
|
||||||
if (indexWriter != null) {
|
|
||||||
try {
|
|
||||||
try {
|
|
||||||
indexWriter.commit();
|
|
||||||
} finally {
|
|
||||||
indexWriter.close(true);
|
|
||||||
}
|
|
||||||
} catch (CorruptIndexException ex) {
|
|
||||||
throw new IndexException("Unable to close an in-memory index", ex);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new IndexException("Unable to close an in-memory index", ex);
|
|
||||||
}
|
|
||||||
if (analyzer != null) {
|
|
||||||
analyzer.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user