SOLR-7014: Collapse identical catch branches in try-catch statements

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1653665 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2015-01-21 21:39:15 +00:00
parent b2f68b23df
commit 0961e4179d
35 changed files with 52 additions and 185 deletions

View File

@ -76,6 +76,10 @@ New Features
* SOLR-6909: Extract atomic update handling logic into AtomicUpdateDocumentMerger class
and enable subclassing. (Steve Davids, yonik)
Other Changes
----------------------
* SOLR-7014: Collapse identical catch branches in try-catch statements. (shalin)
================== 5.0.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

View File

@ -94,9 +94,7 @@ public class ExtractingRequestHandler extends ContentStreamHandlerBase implement
if (config == null) {
try {
config = getDefaultConfig(core.getResourceLoader().getClassLoader());
} catch (MimeTypeException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
} catch (IOException e) {
} catch (MimeTypeException | IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
}

View File

@ -245,11 +245,7 @@ public final class SolrCellBuilder implements CommandBuilder {
try {
parser.parse(inputStream, parsingHandler, metadata, parseContext);
} catch (IOException e) {
throw new MorphlineRuntimeException("Cannot parse", e);
} catch (SAXException e) {
throw new MorphlineRuntimeException("Cannot parse", e);
} catch (TikaException e) {
} catch (IOException | TikaException | SAXException e) {
throw new MorphlineRuntimeException("Cannot parse", e);
}
} finally {

View File

@ -197,14 +197,9 @@ public class EmbeddedSolrServer extends SolrClient
// Now write it out
NamedList<Object> normalized = BinaryResponseWriter.getParsedResponse(req, rsp);
return normalized;
}
catch( IOException iox ) {
} catch( IOException | SolrException iox ) {
throw iox;
}
catch( SolrException sx ) {
throw sx;
}
catch( Exception ex ) {
} catch( Exception ex ) {
throw new SolrServerException( ex );
}
finally {

View File

@ -91,12 +91,9 @@ public class SolrZkServer {
if (zkProps.getClientPortAddress() == null) {
zkProps.setClientPort(Integer.parseInt(solrPort)+1000);
}
} catch (QuorumPeerConfig.ConfigException e) {
} catch (QuorumPeerConfig.ConfigException | IOException e) {
if (zkRun != null)
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
} catch (IOException e) {
if (zkRun != null)
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
}
@ -186,9 +183,7 @@ class SolrZkServerProps extends QuorumPeerConfig {
return cfg;
} catch (IOException e) {
throw new ConfigException("Error processing " + path, e);
} catch (IllegalArgumentException e) {
} catch (IOException | IllegalArgumentException e) {
throw new ConfigException("Error processing " + path, e);
}
}

View File

@ -853,12 +853,10 @@ public final class ZkController {
// Restore the interrupted status
Thread.currentThread().interrupt();
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
} catch (KeeperException e) {
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
} catch (IOException e) {
} catch (KeeperException | IOException e) {
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
}
// in this case, we want to wait for the leader as long as the leader might
// wait for a vote, at least - but also long enough that a large cluster has
@ -2021,14 +2019,10 @@ public final class ZkController {
stateData = zkClient.getData(znodePath, null, new Stat(), false);
} catch (NoNodeException ignoreMe) {
// safe to ignore as this znode will only exist if the leader initiated recovery
} catch (ConnectionLossException cle) {
} catch (ConnectionLossException | SessionExpiredException cle) {
// sort of safe to ignore ??? Usually these are seen when the core is going down
// or there are bigger issues to deal with than reading this znode
log.warn("Unable to read "+znodePath+" due to: "+cle);
} catch (SessionExpiredException see) {
// sort of safe to ignore ??? Usually these are seen when the core is going down
// or there are bigger issues to deal with than reading this znode
log.warn("Unable to read "+znodePath+" due to: "+see);
} catch (Exception exc) {
log.error("Failed to read data from znode "+znodePath+" due to: "+exc);
if (exc instanceof SolrException) {

View File

@ -151,13 +151,7 @@ public class Config {
if (substituteProps) {
DOMUtil.substituteProperties(doc, getSubstituteProperties());
}
} catch (ParserConfigurationException e) {
SolrException.log(log, "Exception during parsing file: " + name, e);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
} catch (SAXException e) {
SolrException.log(log, "Exception during parsing file: " + name, e);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
} catch (TransformerException e) {
} catch (ParserConfigurationException | SAXException | TransformerException e) {
SolrException.log(log, "Exception during parsing file: " + name, e);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}

View File

@ -180,16 +180,12 @@ public class ZkContainer {
log.error("Could not connect to ZooKeeper", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
} catch (IOException e) {
log.error("", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
} catch (KeeperException e) {
} catch (IOException | KeeperException e) {
log.error("", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
}
}
this.zkController = zkController;

View File

@ -726,9 +726,7 @@ public class SnapPuller {
if (waitSearcher[0] != null) {
try {
waitSearcher[0].get();
} catch (InterruptedException e) {
SolrException.log(LOG, e);
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
SolrException.log(LOG, e);
}
}

View File

@ -598,9 +598,7 @@ public class RealTimeGetComponent extends SearchComponent
// TODO: do any kind of validation here?
updates.add(o);
} catch (SolrException e) {
log.warn("Exception reading log for updates", e);
} catch (ClassCastException e) {
} catch (SolrException | ClassCastException e) {
log.warn("Exception reading log for updates", e);
}
}

View File

@ -150,13 +150,9 @@ public abstract class SolrQueryParserBase extends QueryBuilder {
Query res = TopLevelQuery(null); // pass null so we can tell later if an explicit field was provided or not
return res!=null ? res : newBooleanQuery(false);
}
catch (ParseException tme) {
catch (ParseException | TokenMgrError tme) {
throw new SyntaxError("Cannot parse '" +query+ "': " + tme.getMessage(), tme);
}
catch (TokenMgrError tme) {
throw new SyntaxError("Cannot parse '" +query+ "': " + tme.getMessage(), tme);
}
catch (BooleanQuery.TooManyClauses tmc) {
} catch (BooleanQuery.TooManyClauses tmc) {
throw new SyntaxError("Cannot parse '" +query+ "': too many boolean clauses", tmc);
}
}

View File

@ -180,11 +180,8 @@ public class CollationField extends FieldType {
input = loader.openResource(fileName);
String rules = IOUtils.toString(input, "UTF-8");
return new RuleBasedCollator(rules);
} catch (IOException e) {
// io error
throw new RuntimeException(e);
} catch (ParseException e) {
// invalid rules
} catch (IOException | ParseException e) {
// io error or invalid rules
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(input);

View File

@ -836,13 +836,7 @@ class FileExchangeRateProvider implements ExchangeRateProvider {
addRate(tmpRates, fromCurrency, toCurrency, exchangeRate);
}
} catch (SAXException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error parsing currency config.", e);
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error parsing currency config.", e);
} catch (ParserConfigurationException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error parsing currency config.", e);
} catch (XPathExpressionException e) {
} catch (SAXException | XPathExpressionException | ParserConfigurationException | IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error parsing currency config.", e);
}
} catch (IOException e) {

View File

@ -126,13 +126,7 @@ public class EnumField extends PrimitiveFieldType {
enumStringToIntMap.put(valueStr, i);
}
}
catch (ParserConfigurationException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing enums config.", e);
}
catch (SAXException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing enums config.", e);
}
catch (XPathExpressionException e) {
catch (ParserConfigurationException | XPathExpressionException | SAXException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing enums config.", e);
}
}

View File

@ -450,12 +450,9 @@ public class Grouping {
}
try {
searcher.search(query, luceneFilter, collector);
} catch (TimeLimitingCollector.TimeExceededException x) {
} catch (TimeLimitingCollector.TimeExceededException | ExitableDirectoryReader.ExitingReaderException x) {
logger.warn( "Query: " + query + "; " + x.getMessage() );
qr.setPartialResults(true);
} catch (ExitableDirectoryReader.ExitingReaderException e) {
logger.warn( "Query: " + query + "; " + e.getMessage() );
qr.setPartialResults(true);
}
}

View File

@ -234,12 +234,9 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn
((DelegatingCollector)collector).finish();
}
}
catch( TimeLimitingCollector.TimeExceededException x ) {
catch( TimeLimitingCollector.TimeExceededException | ExitableDirectoryReader.ExitingReaderException x ) {
log.warn( "Query: " + query + "; " + x.getMessage() );
qr.setPartialResults(true);
} catch ( ExitableDirectoryReader.ExitingReaderException e) {
log.warn("Query: " + query + "; " + e.getMessage());
qr.setPartialResults(true);
}
}

View File

@ -228,12 +228,9 @@ public class CommandHandler {
try {
searcher.search(query, luceneFilter, collector);
} catch (TimeLimitingCollector.TimeExceededException x) {
} catch (TimeLimitingCollector.TimeExceededException | ExitableDirectoryReader.ExitingReaderException x) {
partialResults = true;
logger.warn( "Query: " + query + "; " + x.getMessage() );
} catch (ExitableDirectoryReader.ExitingReaderException e) {
partialResults = true;
logger.warn( "Query: " + query + "; " + e.getMessage() );
}
if (includeHitCount) {

View File

@ -658,9 +658,7 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState
if (waitSearcher!=null && waitSearcher[0] != null) {
try {
waitSearcher[0].get();
} catch (InterruptedException e) {
SolrException.log(log,e);
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
SolrException.log(log,e);
}
}

View File

@ -66,9 +66,7 @@ public class HdfsUpdateLog extends UpdateLog {
if (future != null) {
try {
future.get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
@ -264,8 +262,6 @@ public class HdfsUpdateLog extends UpdateLog {
return path.getName().startsWith(prefix);
}
});
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}

View File

@ -1302,10 +1302,6 @@ public class UpdateLog implements PluginInfoInitialized {
// versionInfo.unblockUpdates();
}
}
} catch (InterruptedException e) {
SolrException.log(log,e);
} catch (IOException e) {
SolrException.log(log,e);
} catch (Exception e) {
SolrException.log(log,e);
}

View File

@ -429,13 +429,7 @@ public class StatelessScriptUpdateProcessorFactory extends UpdateRequestProcesso
}
}
} catch (ScriptException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Unable to invoke function " + name +
" in script: " +
engine.getScriptFile().getFileName() +
": " + e.getMessage(), e);
} catch (NoSuchMethodException e) {
} catch (ScriptException | NoSuchMethodException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Unable to invoke function " + name +
" in script: " +

View File

@ -125,9 +125,7 @@ public class URLClassifyProcessor extends UpdateRequestProcessor {
document.setField(canonicalUrlFieldname, getCanonicalUrl(normalizedURL));
}
log.debug(document.toString());
} catch (MalformedURLException e) {
log.warn("cannot get the normalized url for \"" + url + "\" due to " + e.getMessage());
} catch (URISyntaxException e) {
} catch (MalformedURLException | URISyntaxException e) {
log.warn("cannot get the normalized url for \"" + url + "\" due to " + e.getMessage());
}
}

View File

@ -992,9 +992,7 @@ public class SolrPluginUtils {
Class pClazz = method.getParameterTypes()[0];
Object val = entry.getValue();
method.invoke(bean, val);
} catch (InvocationTargetException e1) {
throw new RuntimeException("Error invoking setter " + setterName + " on class : " + clazz.getName(), e1);
} catch (IllegalAccessException e1) {
} catch (InvocationTargetException | IllegalAccessException e1) {
throw new RuntimeException("Error invoking setter " + setterName + " on class : " + clazz.getName(), e1);
}
}

View File

@ -559,9 +559,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
createCmd.setDataDir(getDataDir(core3dataDir));
client.request(createCmd);
} catch (SolrServerException e) {
throw new RuntimeException(e);
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
}
}

View File

@ -919,10 +919,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
CollectionAdminRequest.Delete delete = new CollectionAdminRequest.Delete();
delete.setCollectionName(collectionName);
client.request(delete);
} catch (SolrServerException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {

View File

@ -375,13 +375,11 @@ public class FullSolrCloudDistribCmdsTest extends AbstractFullDistribZkTestBase
try {
uReq.process(cloudClient);
uReq.process(controlClient);
} catch (SolrServerException e) {
throw new RuntimeException(e);
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
}
}
}
};

View File

@ -170,10 +170,6 @@ public class LeaderElectionTest extends SolrTestCaseJ4 {
public void run() {
try {
setupOnConnect();
} catch (InterruptedException e) {
log.error("setup failed", e);
es.close();
return;
} catch (Throwable e) {
log.error("setup failed", e);
es.close();
@ -251,9 +247,7 @@ public class LeaderElectionTest extends SolrTestCaseJ4 {
ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(
ZkNodeProps.load(data));
return leaderProps.getCoreUrl();
} catch (NoNodeException e) {
Thread.sleep(500);
} catch (SessionExpiredException e) {
} catch (NoNodeException | SessionExpiredException e) {
Thread.sleep(500);
}
}

View File

@ -55,9 +55,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest {
params.set("async", "1000");
try {
sendRequest(params);
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}
@ -74,9 +72,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest {
try {
message = sendStatusRequestWithRetry(params, MAX_WAIT_TIMEOUT_SECONDS);
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}
@ -90,9 +86,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest {
r = sendRequest(params);
status = (NamedList) r.get("status");
message = (String) status.get("msg");
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}
@ -105,9 +99,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest {
params.set("async", "1001");
try {
sendRequest(params);
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}
@ -117,9 +109,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest {
params.set(OverseerCollectionProcessor.REQUESTID, "1001");
try {
message = sendStatusRequestWithRetry(params, MAX_WAIT_TIMEOUT_SECONDS);
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}
@ -135,9 +125,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest {
params.set("async", "1002");
try {
sendRequest(params);
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}
@ -149,9 +137,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest {
try {
message = sendStatusRequestWithRetry(params, MAX_WAIT_TIMEOUT_SECONDS);
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}
@ -168,9 +154,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest {
params.set("async", "1002");
try {
r = sendRequest(params);
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}

View File

@ -416,9 +416,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
unloadCmd.setCoreName("multiunload" + freezeJ);
try {
adminClient.request(unloadCmd);
} catch (SolrServerException e) {
throw new RuntimeException(e);
} catch (IOException e) {
} catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
}
}

View File

@ -176,9 +176,7 @@ public class ZkSolrClientTest extends AbstractSolrTestCase {
try {
zkClient.makePath("collections/collection4", true);
break;
} catch (KeeperException.SessionExpiredException e) {
} catch (KeeperException.ConnectionLossException e) {
} catch (KeeperException.SessionExpiredException | KeeperException.ConnectionLossException e) {
}
Thread.sleep(1000 * i);
@ -289,9 +287,7 @@ public class ZkSolrClientTest extends AbstractSolrTestCase {
try {
zkClient.getChildren("/collections", this, true);
latch.countDown();
} catch (KeeperException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
} catch (KeeperException | InterruptedException e) {
throw new RuntimeException(e);
}
}

View File

@ -21,7 +21,6 @@ import static java.util.Arrays.asList;
import static org.apache.solr.core.ConfigOverlay.getObjectByPath;
import static org.noggit.ObjectBuilder.getVal;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
@ -99,8 +98,6 @@ public class TestSolrConfigHandlerConcurrent extends AbstractFullDistribZkTestBa
ArrayList errs = new ArrayList();
collectErrors.add(errs);
invokeBulkCall((String)e.getKey() , errs, (Map) e.getValue());
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -22,7 +22,6 @@ import static java.text.MessageFormat.format;
import static org.apache.solr.rest.schema.TestBulkSchemaAPI.getCopyFields;
import static org.apache.solr.rest.schema.TestBulkSchemaAPI.getObj;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@ -98,8 +97,6 @@ public class TestBulkSchemaConcurrent extends AbstractFullDistribZkTestBase {
ArrayList errs = new ArrayList();
collectErrors.add(errs);
invokeBulkCall(finalI,errs);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -82,12 +82,10 @@ public class TestRecoveryHdfs extends SolrTestCaseJ4 {
try {
URI uri = new URI(hdfsUri);
fs = FileSystem.newInstance(uri, new Configuration());
} catch (IOException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
System.setProperty("solr.ulog.dir", hdfsUri + "/solr/shard1");
initCore("solrconfig-tlog.xml","schema15.xml");

View File

@ -458,15 +458,7 @@ public class CloudSolrClient extends SolrClient {
Thread.currentThread().interrupt();
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
} catch (KeeperException e) {
if (zk != null) zk.close();
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
} catch (IOException e) {
if (zk != null) zk.close();
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
} catch (TimeoutException e) {
} catch (KeeperException | TimeoutException | IOException e) {
if (zk != null) zk.close();
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);

View File

@ -92,10 +92,8 @@ public class QueryRequest extends SolrRequest
long endTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
res.setElapsedTime(endTime - startTime);
return res;
} catch (SolrServerException e){
} catch (SolrServerException | SolrException e){
throw e;
} catch (SolrException s){
throw s;
} catch (Exception e) {
throw new SolrServerException("Error executing query", e);
}