List of usage examples for java.lang RuntimeException getCause
public synchronized Throwable getCause()
From source file:org.apache.hadoop.ipc.CallQueueManager.java
private <T extends BlockingQueue<E>> T createCallQueueInstance(Class<T> theClass, int priorityLevels, int maxLen, String ns, Configuration conf) { // Used for custom, configurable callqueues try {// w w w .j a v a 2 s. c o m Constructor<T> ctor = theClass.getDeclaredConstructor(int.class, int.class, String.class, Configuration.class); return ctor.newInstance(priorityLevels, maxLen, ns, conf); } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { throw new RuntimeException(theClass.getName() + " could not be constructed.", e.getCause()); } catch (Exception e) { } // Used for LinkedBlockingQueue, ArrayBlockingQueue, etc try { Constructor<T> ctor = theClass.getDeclaredConstructor(int.class); return ctor.newInstance(maxLen); } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { throw new RuntimeException(theClass.getName() + " could not be constructed.", e.getCause()); } catch (Exception e) { } // Last attempt try { Constructor<T> ctor = theClass.getDeclaredConstructor(); return ctor.newInstance(); } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { throw new RuntimeException(theClass.getName() + " could not be constructed.", e.getCause()); } catch (Exception e) { } // Nothing worked throw new RuntimeException(theClass.getName() + " could not be constructed."); }
From source file:com.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardConsumerTest.java
@SuppressWarnings("unchecked") @Test/*from w w w.j av a2 s.c o m*/ public final void testRecordProcessorThrowable() throws Exception { ShardInfo shardInfo = new ShardInfo("s-0-0", "testToken", null, ExtendedSequenceNumber.TRIM_HORIZON); StreamConfig streamConfig = new StreamConfig(streamProxy, 1, 10, callProcessRecordsForEmptyRecordList, skipCheckpointValidationValue, INITIAL_POSITION_LATEST); ShardConsumer consumer = new ShardConsumer(shardInfo, streamConfig, checkpoint, processor, null, parentShardPollIntervalMillis, cleanupLeasesOfCompletedShards, executorService, metricsFactory, taskBackoffTimeMillis, KinesisClientLibConfiguration.DEFAULT_SKIP_SHARD_SYNC_AT_STARTUP_IF_LEASES_EXIST); when(leaseManager.getLease(anyString())).thenReturn(null); when(checkpoint.getCheckpoint(anyString())).thenReturn(new ExtendedSequenceNumber("123")); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.WAITING_ON_PARENT_SHARDS))); consumer.consumeShard(); // submit BlockOnParentShardTask Thread.sleep(50L); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.WAITING_ON_PARENT_SHARDS))); verify(processor, times(0)).initialize(any(InitializationInput.class)); // Throw Error when IRecordProcessor.initialize() is invoked. doThrow(new Error("ThrowableTest")).when(processor).initialize(any(InitializationInput.class)); consumer.consumeShard(); // submit InitializeTask Thread.sleep(50L); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.INITIALIZING))); verify(processor, times(1)).initialize(any(InitializationInput.class)); try { // Checking the status of submitted InitializeTask from above should throw exception. consumer.consumeShard(); fail("ShardConsumer should have thrown exception."); } catch (RuntimeException e) { assertThat(e.getCause(), instanceOf(ExecutionException.class)); } Thread.sleep(50L); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.INITIALIZING))); verify(processor, times(1)).initialize(any(InitializationInput.class)); doNothing().when(processor).initialize(any(InitializationInput.class)); consumer.consumeShard(); // submit InitializeTask again. Thread.sleep(50L); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.INITIALIZING))); verify(processor, times(2)).initialize(any(InitializationInput.class)); // Checking the status of submitted InitializeTask from above should pass. consumer.consumeShard(); Thread.sleep(50L); assertThat(consumer.getCurrentState(), is(equalTo(ConsumerStates.ShardConsumerState.PROCESSING))); }
From source file:org.apache.hadoop.hbase.catalog.CatalogTracker.java
/** * Starts the catalog tracker./*from www . j av a2 s .c o m*/ * Determines current availability of catalog tables and ensures all further * transitions of either region are tracked. * @throws IOException * @throws InterruptedException */ public void start() throws IOException, InterruptedException { LOG.debug("Starting catalog tracker " + this); try { this.metaRegionTracker.start(); } catch (RuntimeException e) { Throwable t = e.getCause(); this.abortable.abort(e.getMessage(), t); throw new IOException("Attempt to start meta tracker failed.", t); } }
From source file:com.qualogy.qafe.mgwt.server.processor.impl.EventProcessorImpl.java
public GDataObject execute(EventDataGVO eventData, ApplicationIdentifier appId, SessionContainer ss) { ApplicationContext context = ApplicationCluster.getInstance().get(appId); EventHandler eventHandler = context.getEventHandler(); StopWatch stopWatch = new StopWatch(); stopWatch.start();//from w ww. j a v a 2 s . com GDataObject data = new GDataObject(); data.setSenderId(eventData.getSender()); data.setListenerType(eventData.getListenerType()); data.setEventId(eventData.getEventId()); data.setUuid(eventData.getUuid()); data.setParent(eventData.getParent()); ApplicationStoreIdentifier appStoreId = new ApplicationStoreIdentifier(eventData.getUuid()); String[] senderInfo = StringUtils.split(eventData.getSender(), '|'); logger.fine(eventData.toString() + ", WindowID " + senderInfo[1]); String windowId = ""; // if (senderInfo.length==2 || senderInfo.length==3){ if (senderInfo.length == 2 || senderInfo.length == 3) { if (senderInfo.length == 2) {// dealing with a RootPanel only windowId = senderInfo[0]; } if (senderInfo.length == 3) { windowId = senderInfo[1]; } try { List<InputVariable> inputVariables = new ArrayList<InputVariable>(); if (eventData.getInputVariables() != null) { for (InputVariableGVO inVar : eventData.getInputVariables()) { inputVariables.add( new InputVariable(inVar.getName(), inVar.getReference(), inVar.getDefaultValue(), inVar.getComponentValue(), convert(inVar.getDataContainerObject()))); } } EventDataObject eventDataObject = new EventDataObject(eventData.getEventId(), eventData.getSourceInfo(), appId, eventData.getListenerType(), inputVariables, eventData.getInternalVariables(), senderInfo[0], eventData.getSenderName(), windowId, eventData.getUuid(), eventData.getUserUID(), eventData.getWindowSession(), eventData.getRequest(), eventData.getParameters(), eventData.getMouse()); /* * EventDataContainer edci = * convert(eventData.getDataContainer()); if (edci != null) { * eventDataObject.getInputVariables().add(edci); } */ eventDataObject.setApplicationStoreIdentifier(appStoreId); // Collection builtInFunctionsToExecute // =eventHandler.manage(senderInfo[0], // eventId,windowId,params,appId,event); Collection<?> builtInFunctionsToExecute = eventHandler.manage(eventDataObject); Iterator<?> itr = builtInFunctionsToExecute.iterator(); Collection<BuiltInFunctionGVO> builtInFunctions = new ArrayList<BuiltInFunctionGVO>(); while (itr.hasNext()) { BuiltInFunction builtInFunctionToExecute = (BuiltInFunction) itr.next(); BuiltInFunctionGVO builtInFunction = EventUIAssembler .convert((EventItem) builtInFunctionToExecute, eventData, context, ss); if (builtInFunction != null) { builtInFunctions.add(builtInFunction); } } data.setFunctions((BuiltInFunctionGVO[]) builtInFunctions.toArray(new BuiltInFunctionGVO[] {})); } catch (RuntimeException e) { ExceptionHelper.printStackTrace(e); throw e; } catch (ExternalException e) { ExceptionHelper.printStackTrace(e.getCause()); throw new RuntimeException(e.getMessage(), e); } } else { logger.warning("Error in sender string (is not partionable in size 2) : " + eventData.getSender()); } stopWatch.stop(); logger.warning("EventProcessorImpl uuid:[" + eventData.getUuid() + "], sender[" + eventData.getSender() + "], eventId [" + eventData.getEventName() + "] took [" + stopWatch.getTime() + "]ms "); return data; }
From source file:com.thoughtworks.go.server.GoServerContextHandlersTest.java
@Test public void shouldStopServerAndThrowExceptionWhenServerFailsToStartWithAnUnhandledException() throws Exception { final JettyServer server = mock(JettyServer.class); final WebAppContext webAppContext = mock(WebAppContext.class); when(server.getContainer()).thenReturn(new Container()); when(server.getServer()).thenReturn(mock(Server.class)); GoServer goServer = new GoServer() { @Override//from w w w .jav a2s. co m WebAppContext webApp() throws IOException, SAXException, ClassNotFoundException, UnavailableException { return webAppContext; } @Override JettyServer createServer() { return server; } }; doNothing().when(server).start(); doNothing().when(server).stop(); doReturn(webAppContext).when(server).webAppContext(); when(webAppContext.getUnavailableException()) .thenReturn(new RuntimeException("Some unhandled server startup exception")); try { goServer.startServer(); fail("Should have thrown an exception"); } catch (RuntimeException e) { assertThat(e.getMessage(), is("Failed to start Go server.")); assertThat(e.getCause().getMessage(), is("Some unhandled server startup exception")); } InOrder inOrder = inOrder(server, webAppContext); inOrder.verify(server).start(); inOrder.verify(webAppContext).getUnavailableException(); inOrder.verify(server).stop(); }
From source file:org.mifos.customers.client.persistence.ClientPersistenceIntegrationTest.java
public void testShouldThrowExceptionWhenTryingToCreateACustomerWithSameGovtId() throws Exception { setUpClients();/*from ww w .ja va2 s. com*/ localTestClient = createActiveClientWithGovtId(); try { TestObjectFactory.createClient(this.getClass().getSimpleName() + " Duplicate Client", CustomerStatus.CLIENT_ACTIVE, group, null, GOVT_ID, new Date(1222333444000L)); Assert.fail("Should have thrown exception on creating a duplicate client with same government id"); } catch (RuntimeException e) { Assert.assertEquals(CustomerConstants.DUPLICATE_GOVT_ID_EXCEPTION, ((CustomerException) e.getCause()).getKey()); } }
From source file:com.thoughtworks.go.config.GoConfigDataSourceTest.java
@Test public void shouldThrowConfigMergeExceptionWhenConfigMergeFeatureIsTurnedOff() throws Exception { String firstMd5 = dataSource.forceLoad(dataSource.fileLocation()).configForEdit.getMd5(); goConfigFileDao.updateConfig(configHelper.addPipelineCommand(firstMd5, "p0", "s0", "b0")); String originalMd5 = dataSource.forceLoad(dataSource.fileLocation()).configForEdit.getMd5(); goConfigFileDao.updateConfig(configHelper.addPipelineCommand(originalMd5, "p1", "s1", "j1")); GoConfigHolder goConfigHolder = dataSource.forceLoad(dataSource.fileLocation()); systemEnvironment.set(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE, Boolean.FALSE); try {/*from w w w . j av a 2 s . c om*/ dataSource.writeWithLock(configHelper.changeJobNameCommand(originalMd5, "p0", "s0", "b0", "j0"), goConfigHolder); fail("Should throw ConfigMergeException"); } catch (RuntimeException e) { ConfigMergeException cme = (ConfigMergeException) e.getCause(); assertThat(cme.getMessage(), is(ConfigFileHasChangedException.CONFIG_CHANGED_PLEASE_REFRESH)); } }
From source file:net.sourceforge.pmd.ant.PMDTask.java
private void handleError(RuleContext ctx, Report errorReport, RuntimeException pmde) { pmde.printStackTrace();// ww w . j a v a 2s . c o m log(pmde.toString(), Project.MSG_VERBOSE); Throwable cause = pmde.getCause(); if (cause != null) { StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter); cause.printStackTrace(printWriter); log(strWriter.toString(), Project.MSG_VERBOSE); IOUtils.closeQuietly(printWriter); if (StringUtil.isNotEmpty(cause.getMessage())) { log(cause.getMessage(), Project.MSG_VERBOSE); } } if (failOnError) { throw new BuildException(pmde); } errorReport.addError(new Report.ProcessingError(pmde.getMessage(), ctx.getSourceCodeFilename())); }
From source file:org.bpmscript.process.memory.MemoryBpmScriptManager.java
/** * @param results the results to sort//ww w . j a v a 2s .c o m * @param orderBys the properties to sort by * @throws BpmScriptException if something goes wrong (e.g. one of the properties is not valid) */ private void sortResults(List<IInstance> results, final List<IOrderBy> orderBys) throws BpmScriptException { if (orderBys != null && orderBys.size() > 0) { try { Collections.sort(results, new ReflectionComparator(orderBys)); } catch (RuntimeException e) { Throwable cause = e.getCause(); if (cause != null && cause instanceof BpmScriptException) { throw (BpmScriptException) cause; } else { throw e; } } } }
From source file:com.owncloud.android.network.AdvancedSslSocketFactory.java
/** * Verifies the identity of the server. * // ww w . j a v a 2 s.co m * The server certificate is verified first. * * Then, the host name is compared with the content of the server certificate using the current host name verifier, if any. * @param socket */ private void verifyPeerIdentity(String host, int port, Socket socket) throws IOException { try { CertificateCombinedException failInHandshake = null; /// 1. VERIFY THE SERVER CERTIFICATE through the registered TrustManager (that should be an instance of AdvancedX509TrustManager) try { SSLSocket sock = (SSLSocket) socket; // a new SSLSession instance is created as a "side effect" sock.startHandshake(); } catch (RuntimeException e) { if (e instanceof CertificateCombinedException) { failInHandshake = (CertificateCombinedException) e; } else { Throwable cause = e.getCause(); Throwable previousCause = null; while (cause != null && cause != previousCause && !(cause instanceof CertificateCombinedException)) { previousCause = cause; cause = cause.getCause(); } if (cause != null && cause instanceof CertificateCombinedException) { failInHandshake = (CertificateCombinedException) cause; } } if (failInHandshake == null) { throw e; } failInHandshake.setHostInUrl(host); } /// 2. VERIFY HOSTNAME SSLSession newSession = null; boolean verifiedHostname = true; if (mHostnameVerifier != null) { if (failInHandshake != null) { /// 2.1 : a new SSLSession instance was NOT created in the handshake X509Certificate serverCert = failInHandshake.getServerCertificate(); try { mHostnameVerifier.verify(host, serverCert); } catch (SSLException e) { verifiedHostname = false; } } else { /// 2.2 : a new SSLSession instance was created in the handshake newSession = ((SSLSocket) socket).getSession(); if (!mTrustManager.isKnownServer((X509Certificate) (newSession.getPeerCertificates()[0]))) { verifiedHostname = mHostnameVerifier.verify(host, newSession); } } } /// 3. Combine the exceptions to throw, if any if (!verifiedHostname) { SSLPeerUnverifiedException pue = new SSLPeerUnverifiedException( "Names in the server certificate do not match to " + host + " in the URL"); if (failInHandshake == null) { failInHandshake = new CertificateCombinedException( (X509Certificate) newSession.getPeerCertificates()[0]); failInHandshake.setHostInUrl(host); } failInHandshake.setSslPeerUnverifiedException(pue); pue.initCause(failInHandshake); throw pue; } else if (failInHandshake != null) { SSLHandshakeException hse = new SSLHandshakeException("Server certificate could not be verified"); hse.initCause(failInHandshake); throw hse; } } catch (IOException io) { try { socket.close(); } catch (Exception x) { // NOTHING - irrelevant exception for the caller } throw io; } }