Apache Lucene open-source search software
LUCENE-6193: Collapse identical catch branches in try-catch statements
Shalin Shekhar Mangar66eba44b54d8
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex ec29ea7a005..b5a931ba226 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -41,6 +41,11 @@ Optimizations* LUCENE-6184: Make BooleanScorer only score windows that containmatches. (Adrien Grand)+Other++* LUCENE-6193: Collapse identical catch branches in try-catch statements.+ (shalin)+======================= Lucene 5.0.0 =======================New Featuresdiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.javaindex d8a14f302b0..ccdfc49f1fa 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java@@ -135,9 +135,7 @@ public class TestFactories extends BaseTokenStreamTestCase {AbstractAnalysisFactory factory = null;try {factory = ctor.newInstance(args);- } catch (InstantiationException e) {- throw new RuntimeException(e);- } catch (IllegalAccessException e) {+ } catch (InstantiationException | IllegalAccessException e) {throw new RuntimeException(e);} catch (InvocationTargetException e) {if (e.getCause() instanceof IllegalArgumentException) {diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.javaindex 0fddc539143..ced8b729f96 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java@@ -712,10 +712,8 @@ public class TestRandomChains extends BaseTokenStreamTestCase {} else {Rethrow.rethrow(cause);}- } catch (IllegalAccessException iae) {+ } catch (IllegalAccessException | InstantiationException iae) {Rethrow.rethrow(iae);- } catch (InstantiationException ie) {- Rethrow.rethrow(ie);}return null; // no success}diff --git a/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizer.java b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizer.javaindex 0b8fc39b28a..c0d7389a14e 100644--- a/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizer.java+++ b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizer.java@@ -58,9 +58,7 @@ public final class UIMAAnnotationsTokenizer extends BaseUIMATokenizer {protected void initializeIterator() throws IOException {try {analyzeInput();- } catch (AnalysisEngineProcessException e) {- throw new IOException(e);- } catch (ResourceInitializationException e) {+ } catch (AnalysisEngineProcessException | ResourceInitializationException e) {throw new IOException(e);}finalOffset = correctOffset(cas.getDocumentText().length());diff --git a/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizer.java b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizer.javaindex 65fd2ef2142..fbf1d8e8293 100644--- a/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizer.java+++ b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizer.java@@ -70,9 +70,7 @@ public final class UIMATypeAwareAnnotationsTokenizer extends BaseUIMATokenizer {protected void initializeIterator() throws IOException {try {analyzeInput();- } catch (AnalysisEngineProcessException e) {- throw new IOException(e);- } catch (ResourceInitializationException e) {+ } catch (AnalysisEngineProcessException | ResourceInitializationException e) {throw new IOException(e);}featurePath = cas.createFeaturePath();diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.javaindex e8a9b3825a2..768a253ccdf 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java@@ -202,10 +202,8 @@ public class EnwikiContentSource extends ContentSource {}}}- } catch (SAXException sae) {+ } catch (SAXException | IOException sae) {throw new RuntimeException(sae);- } catch (IOException ioe) {- throw new RuntimeException(ioe);} finally {synchronized(this) {threadDone = true;diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.javaindex 5951ae13e9b..b0a234a0596 100644--- a/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java@@ -170,9 +170,7 @@ abstract class ByteBufferIndexInput extends IndexInput implements RandomAccessInthis.curBufIndex = bi;this.curBuf = b;}- } catch (ArrayIndexOutOfBoundsException aioobe) {- throw new EOFException("seek past EOF: " + this);- } catch (IllegalArgumentException iae) {+ } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException e) {throw new EOFException("seek past EOF: " + this);} catch (NullPointerException npe) {throw new AlreadyClosedException("Already closed: " + this);@@ -198,9 +196,7 @@ abstract class ByteBufferIndexInput extends IndexInput implements RandomAccessInb.position((int) (pos & chunkSizeMask));this.curBufIndex = bi;this.curBuf = b;- } catch (ArrayIndexOutOfBoundsException aioobe) {- throw new EOFException("seek past EOF: " + this);- } catch (IllegalArgumentException iae) {+ } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException aioobe) {throw new EOFException("seek past EOF: " + this);} catch (NullPointerException npe) {throw new AlreadyClosedException("Already closed: " + this);diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.javaindex 4a760e7bbd8..8a6c6ce7a1e 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java@@ -634,9 +634,7 @@ public class TestIndexWriterWithThreads extends LuceneTestCase {writerRef.get().prepareCommit();}writerRef.get().commit();- } catch (AlreadyClosedException ace) {- // ok- } catch (NullPointerException npe) {+ } catch (AlreadyClosedException | NullPointerException ace) {// ok} finally {commitLock.unlock();@@ -648,11 +646,7 @@ public class TestIndexWriterWithThreads extends LuceneTestCase {}try {writerRef.get().addDocument(docs.nextDoc());- } catch (AlreadyClosedException ace) {- // ok- } catch (NullPointerException npe) {- // ok- } catch (AssertionError ae) {+ } catch (AlreadyClosedException | NullPointerException | AssertionError ace) {// ok}break;diff --git a/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java b/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.javaindex c6f5d8b6866..7879e7c5133 100644--- a/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java+++ b/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java@@ -197,9 +197,7 @@ public class TestUnicodeUtil extends LuceneTestCase {assertFalse(rc == -1);assertEquals(cpString.substring(rs, rs + rc), str);continue;- } catch (IndexOutOfBoundsException e1) {- // Ignored.- } catch (IllegalArgumentException e2) {+ } catch (IndexOutOfBoundsException | IllegalArgumentException e1) {// Ignored.}assertTrue(rc == -1);diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.javaindex 2d10e68d66e..a4d7797ea21 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java@@ -117,18 +117,12 @@ public abstract class QueryParserBase extends QueryBuilder implements CommonQuerQuery res = TopLevelQuery(field);return res!=null ? res : newBooleanQuery(false);}- catch (ParseException tme) {+ catch (ParseException | TokenMgrError tme) {// rethrow to include the original query:ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());e.initCause(tme);throw e;- }- catch (TokenMgrError tme) {- ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());- e.initCause(tme);- throw e;- }- catch (BooleanQuery.TooManyClauses tmc) {+ } catch (BooleanQuery.TooManyClauses tmc) {ParseException e = new ParseException("Cannot parse '" +query+ "': too many boolean clauses");e.initCause(tmc);throw e;diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/messages/NLS.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/messages/NLS.javaindex 06b65ca7769..ea319b5c0bb 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/messages/NLS.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/messages/NLS.java@@ -149,9 +149,7 @@ public class NLS {try {field.set(null, field.getName());validateMessage(field.getName(), clazz);- } catch (IllegalArgumentException e) {- // should not happen- } catch (IllegalAccessException e) {+ } catch (IllegalArgumentException | IllegalAccessException e) {// should not happen}}diff --git a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.javaindex 1cf12bae427..310399f2829 100644--- a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java+++ b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java@@ -419,9 +419,7 @@ public class IndexAndTaxonomyReplicationClientTest extends ReplicatorTestCase {checker.setInfoStream(new PrintStream(bos, false, IOUtils.UTF_8), false);try {indexStatus = checker.checkIndex(null);- } catch (IOException ioe) {- // ok: we fallback below- } catch (RuntimeException re) {+ } catch (IOException | RuntimeException ioe) {// ok: we fallback below}}diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseTermVectorsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseTermVectorsFormatTestCase.javaindex 16655ea1b81..4f9f958b106 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseTermVectorsFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseTermVectorsFormatTestCase.java@@ -511,9 +511,7 @@ public abstract class BaseTermVectorsFormatTestCase extends BaseIndexFileFormatTtry {docsAndPositionsEnum.nextPosition();fail();- } catch (Exception e) {- // ok- } catch (AssertionError e) {+ } catch (Exception | AssertionError e) {// ok}}diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.javaindex 72c8621c047..d11528705e4 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java@@ -689,10 +689,8 @@ public abstract class LuceneTestCase extends Assert {m.setAccessible(true);try {m.invoke(IndexWriter.class, limit);- } catch (IllegalAccessException iae) {+ } catch (IllegalAccessException | InvocationTargetException iae) {throw new RuntimeException(iae);- } catch (InvocationTargetException ite) {- throw new RuntimeException(ite);}}