List of usage examples for java.lang RuntimeException getCause
public synchronized Throwable getCause()
From source file:org.fuin.utils4j.Utils4JTest.java
/** * @testng.test//from ww w. ja va 2s . c o m */ public final void testCreateInstanceIllegalAccess() { try { Utils4J.createInstance(ClassWithPrivateConstructor.class.getName()); Assert.fail(); } catch (final RuntimeException ex) { Assert.assertTrue(ex.getCause() instanceof IllegalAccessException); } }
From source file:org.wso2.carbon.registry.extensions.handlers.utils.SchemaProcessor.java
public String importSchemaToRegistry(RequestContext requestContext, String resourcePath, String commonLocation, boolean processIncludes, boolean disableSymlinkCreation) throws RegistryException { resourceName = resourcePath.substring(resourcePath.lastIndexOf(RegistryConstants.PATH_SEPARATOR) + 1); String url = requestContext.getSourceURL(); String version = requestContext.getResource().getProperty("version"); if (version == null) { version = CommonConstants.SCHEMA_VERSION_DEFAULT_VALUE; }//from ww w . j a v a2s . co m XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection(); xmlSchemaCollection.setBaseUri(url); baseURI = url; InputSource inputSource = new InputSource(url); try { // Here we assue schema is correct. Schema validation is beyond our scope, so we don't // bother with a ValidationEventHandler. XmlSchema xmlSchema = xmlSchemaCollection.read(inputSource, null); evaluateSchemasRecursively(xmlSchema, null, false, true); } catch (URISyntaxException e) { String msg = "Syntax error in the uri"; log.error(msg, e); throw new RegistryException(msg, e);//to preserver the exception handling execution path of the rest of the //application. } catch (RuntimeException re) { String msg = "Could not read the XML Schema Definition file. "; if (re.getCause() instanceof org.apache.ws.commons.schema.XmlSchemaException) { msg += re.getCause().getMessage(); log.error(msg, re); throw new RegistryException(msg); } throw new RegistryException(msg, re); } updateSchemaPaths(commonLocation, version, requestContext); updateSchemaInternalsAndAssociations(); String symlinkLocation = requestContext.getResource().getProperty(RegistryConstants.SYMLINK_PROPERTY_NAME); Resource metaResource = requestContext.getResource(); String path = saveSchemaToRegistry(requestContext, resourcePath, symlinkLocation, metaResource, disableSymlinkCreation); // should depend on the central location / relative location flag persistAssociations(path); return path; }
From source file:org.lockss.util.ObjectSerializerTester.java
/** * <p>Tests that an {@link InterruptedIOException} is thrown when * I/O fails because of an underlying/*from w w w. jav a 2s . co m*/ * {@link InterruptedIOException}.</p> * @throws Exception if an unexpected or unhandled problem arises. */ public void testThrowsInterruptedIOException() throws Exception { // Make a sample object final ExtMapBean obj = makeSample_ExtMapBean(); // Define variant actions DoSomething[] actions = new DoSomething[] { // With a Writer new DoSomething() { public void doSomething(ObjectSerializer serializer) throws Exception { serializer.serialize(new StringWriter() { public void write(char[] cbuf, int off, int len) { throw new RuntimeException(new InterruptedIOException()); } }, obj); } }, // With an OutputStream new DoSomething() { public void doSomething(ObjectSerializer serializer) throws Exception { serializer.serialize(new ByteArrayOutputStream() { public synchronized void write(byte[] b, int off, int len) { throw new RuntimeException(new InterruptedIOException()); } }, obj); } }, // With a Reader new DoSomething() { public void doSomething(ObjectSerializer serializer) throws Exception { serializer.deserialize(new StringReader("") { public int read(char[] cbuf, int off, int len) throws IOException { throw new InterruptedIOException(); } }); } }, // With an InputStream new DoSomething() { public void doSomething(ObjectSerializer serializer) throws Exception { serializer.deserialize(new StringInputStream("") { public int read(byte[] b, int off, int len) throws IOException { throw new InterruptedIOException(); } }); } }, }; // For each variant action... for (int action = 0; action < actions.length; ++action) { logger.debug("Begin with action " + action); // For each type of serializer... ObjectSerializer[] serializers = getObjectSerializers_ExtMapBean(); for (int serializer = 0; serializer < serializers.length; ++serializer) { logger.debug("Begin with deserializer " + serializer); try { // Perform variant action actions[action].doSomething(serializers[serializer]); fail("Should have thrown InterruptedIOException (" + action + "," + serializer + ")"); } catch (InterruptedIOException ignore) { // success } catch (RuntimeException re) { if (re.getCause() != null && re.getCause() instanceof InterruptedIOException) { fail("Should have thrown InterruptedIOException (" + action + "," + serializer + ")"); } else { // success } } } } }
From source file:org.apache.hadoop.ha.ZKFailoverController.java
public int run(final String[] args) throws Exception { if (!localTarget.isAutoFailoverEnabled()) { LOG.fatal("Automatic failover is not enabled for " + localTarget + "." + " Please ensure that automatic failover is enabled in the " + "configuration before running the ZK failover controller."); return ERR_CODE_AUTO_FAILOVER_NOT_ENABLED; }/* w w w . j a v a 2 s .co m*/ loginAsFCUser(); try { return SecurityUtil.doAsLoginUserOrFatal(new PrivilegedAction<Integer>() { @Override public Integer run() { try { return doRun(args); } catch (Exception t) { throw new RuntimeException(t); } finally { if (elector != null) { elector.terminateConnection(); } } } }); } catch (RuntimeException rte) { LOG.fatal("The failover controller encounters runtime error: " + rte); throw (Exception) rte.getCause(); } }
From source file:org.seasar.doma.boot.autoconfigure.DomaPersistenceExceptionTranslator.java
@Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (!(ex instanceof JdbcException)) { // Fallback to other translators if not JdbcException return null; }//from ww w . jav a 2s . c o m if (ex instanceof OptimisticLockException) { return new OptimisticLockingFailureException(ex.getMessage(), ex); } else if (ex instanceof UniqueConstraintException) { return new DuplicateKeyException(ex.getMessage(), ex); } else if (ex instanceof NonUniqueResultException || ex instanceof NonSingleColumnException) { return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex); } else if (ex instanceof NoResultException) { return new EmptyResultDataAccessException(ex.getMessage(), 1, ex); } else if (ex instanceof UnknownColumnException || ex instanceof ResultMappingException) { return new TypeMismatchDataAccessException(ex.getMessage(), ex); } if (ex.getCause() instanceof SQLException) { SQLException e = (SQLException) ex.getCause(); String sql = null; if (ex instanceof SqlExecutionException) { sql = ((SqlExecutionException) ex).getRawSql(); } return translator.translate(ex.getMessage(), sql, e); } return new UncategorizedDataAccessException(ex.getMessage(), ex) { }; }
From source file:de.tud.inf.db.sparqlytics.olap.Compute.java
/** * Extends the given runtime exception with the given query string. * //from w w w .jav a2s . c o m * @param ex the exception to extend * @param query the query to add to the exception message * @return the extended exception */ protected RuntimeException extendRuntimeException(RuntimeException ex, String query) { StringBuilder builder = new StringBuilder(); String message = ex.getMessage(); if (message != null) { builder.append(message).append(System.lineSeparator()); } builder.append(ex.getClass().getSimpleName()).append(" caused by query:").append(System.lineSeparator()); builder.append(query); RuntimeException extended = new RuntimeException(builder.toString(), ex.getCause()); extended.setStackTrace(ex.getStackTrace()); return extended; }
From source file:io.personium.core.model.impl.es.CellEsImpl.java
@Override public Box getBoxForName(String boxName) { if (Box.DEFAULT_BOX_NAME.equals(boxName)) { return new Box(this, null); }//from w ww . jav a2 s.c o m // URl???Box????????Box??????null?? if (!validatePropertyRegEx(boxName, Common.PATTERN_NAME)) { return null; } // ??Box??? Box cachedBox = BoxCache.get(boxName, this); if (cachedBox != null) { return cachedBox; } Box loadedBox = null; try { ODataProducer op = ModelFactory.ODataCtl.cellCtl(this); EntityResponse er = op.getEntity(Box.EDM_TYPE_NAME, OEntityKey.create(boxName), null); loadedBox = new Box(this, er.getEntity()); BoxCache.cache(loadedBox); return loadedBox; } catch (RuntimeException e) { if (e.getCause() instanceof CheckedOperationTimeoutException) { return loadedBox; } else { return null; } } }
From source file:org.wso2.carbon.registry.extensions.handlers.utils.SchemaProcessor.java
public String putSchemaToRegistry(RequestContext requestContext, String resourcePath, String commonLocation, boolean processIncludes, boolean disableSymlinkCreation) throws RegistryException { boolean isDefaultEnvironment = true; String currentSchemaLocation = null; String currentEnvironment = null; String masterVersion = null;/* ww w .j a va2 s . c o m*/ List<String> dependeinciesList = new ArrayList<String>(); resourceName = resourcePath.substring(resourcePath.lastIndexOf(RegistryConstants.PATH_SEPARATOR) + 1); XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( (byte[]) requestContext.getResource().getContent()); InputSource inputSource = new InputSource(byteArrayInputStream); String url = "http://this.schema.needs/a/valid/source/url/to/proceed.xsd"; String version = requestContext.getResource().getProperty("version"); if (version == null) { version = CommonConstants.SCHEMA_VERSION_DEFAULT_VALUE; requestContext.getResource().setProperty("version", version); } if (requestContext.getSourceURL() != null) { url = requestContext.getSourceURL(); } XmlSchema xmlSchema; try { xmlSchemaCollection.setBaseUri(url); xmlSchema = xmlSchemaCollection.read(inputSource, null); xmlSchema.setSourceURI(url); evaluateSchemasRecursively(xmlSchema, null, false, true); } catch (URISyntaxException e) { String msg = "Syntax error in the uri"; log.error(msg, e); throw new RegistryException(msg, e);//to preserver the exception handling execution path of the rest of the //application. } catch (RuntimeException re) { String msg = "Could not read the XML Schema Definition file. "; if (re.getCause() instanceof org.apache.ws.commons.schema.XmlSchemaException) { msg += re.getCause().getMessage(); log.error(msg, re); throw new RegistryException(msg); } throw new RegistryException(msg, re); } String path = null; // should depend on the central location / relative location flag if (!resourcePath.equals(RegistryConstants.PATH_SEPARATOR + resourceName) & !resourcePath.contains(commonLocation) & (registry.resourceExists(resourcePath))) { if (currentSchemaLocation == null) { currentEnvironment = resourcePath.substring(0, resourcePath.indexOf(CommonUtil .derivePathFragmentFromNamespace(xmlSchema.getTargetNamespace()).replace("//", "/"))); currentSchemaLocation = currentEnvironment .substring(RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH.length() + 1); } if (masterVersion == null) { String namespaceSegment = CommonUtil.derivePathFragmentFromNamespace(xmlSchema.getTargetNamespace()) .replace("//", "/"); String suffix = resourcePath .substring(resourcePath.indexOf(namespaceSegment) + namespaceSegment.length()); masterVersion = suffix.substring(0, suffix.indexOf(RegistryConstants.PATH_SEPARATOR)); } isDefaultEnvironment = false; Association[] associations = registry.getAssociations(resourcePath, CommonConstants.DEPENDS); for (Association association : associations) { if (association.getSourcePath().equals(resourcePath)) { dependeinciesList.add(association.getDestinationPath()); } } dependeinciesList.add(resourcePath); // updateSchemaPaths(currentEnvironment,masterVersion,dependeinciesList); // updateSchemaInternalsAndAssociations(); String symlinkLocation = RegistryUtils.getAbsolutePath(requestContext.getRegistryContext(), requestContext.getResource().getProperty(RegistryConstants.SYMLINK_PROPERTY_NAME)); Resource metaResource = requestContext.getResource(); path = saveSchemasToRegistry(requestContext, currentEnvironment, symlinkLocation, metaResource, masterVersion, dependeinciesList, disableSymlinkCreation); persistAssociations(path); } else { updateSchemaPaths(commonLocation, version, requestContext); updateSchemaInternalsAndAssociations(); String symlinkLocation = RegistryUtils.getAbsolutePath(requestContext.getRegistryContext(), requestContext.getResource().getProperty(RegistryConstants.SYMLINK_PROPERTY_NAME)); Resource metaResource = requestContext.getResource(); path = saveSchemaToRegistry(requestContext, resourcePath, symlinkLocation, metaResource, disableSymlinkCreation); persistAssociations(path); } return path; }
From source file:org.lsc.AbstractSynchronize.java
public void run() { counter.incrementCountAll();// w w w .ja v a 2 s.c o m try { run(abstractSynchronize.getBean(task, fromSource ? task.getSourceService() : task.getDestinationService(), id.getKey(), id.getValue(), true, fromSource)); } catch (RuntimeException e) { counter.incrementCountError(); abstractSynchronize.logActionError(null, id.getValue(), e); if (e.getCause() instanceof LscServiceCommunicationException) { AbstractSynchronize.LOGGER.error("Connection lost! Aborting."); } } catch (Exception e) { counter.incrementCountError(); abstractSynchronize.logActionError(null, id.getValue(), e); } }
From source file:common.exceptions.support.RuntimeExceptionMapper.java
/** * {@inheritDoc}//from ww w. ja v a 2s.c o m */ @Override public Response toResponse(RuntimeException re) { ServiceException ex; Response response; if (re instanceof ValidationException) { ex = (ValidationException) re; response = ResponseBuilder.build(Response.Status.fromStatusCode(ex.getEventLogId().getResponseId()), ((ValidationException) re).getMessages()); } else if (re instanceof ServiceException) { ex = (ServiceException) re; response = ResponseBuilder.build(Response.Status.fromStatusCode(ex.getEventLogId().getResponseId()), String.valueOf(ex.getEventLogId().getEventId()), ex.getMessage()); } else { ex = new ServiceException(re, HttpEventLogId.UnexpectedException, ExceptionUtils.getRootCauseMessage(re)); response = ResponseBuilder.build(Response.Status.INTERNAL_SERVER_ERROR, String.valueOf(ex.getStatusCode()), ExceptionUtils.getFullStackTrace(re)); } if (re instanceof WebApplicationException) { if (re.getCause() instanceof ServiceException) { ex = (ServiceException) re.getCause(); response = ResponseBuilder.build(Response.Status.INTERNAL_SERVER_ERROR, String.valueOf(ex.getEventLogId().getEventId()), ex.getMessage()); } else { ex = new ServiceException(re, HttpEventLogId.UnexpectedException, ExceptionUtils.getRootCauseMessage(re)); response = ResponseBuilder.build( Response.Status.fromStatusCode(((WebApplicationException) re).getResponse().getStatus()), String.valueOf(((WebApplicationException) re).getResponse().getStatus()), ExceptionUtils.getFullStackTrace(re)); } } ex.log(LOGGER); return response; }