List of usage examples for java.lang IllegalStateException getCause
public synchronized Throwable getCause()
From source file:com.fiveamsolutions.nci.commons.util.MailUtils.java
/** * Get the current mail session.//ww w. j a v a 2s . co m * @return return the current mail session */ public static Session getMailSession() { try { return (Session) JndiUtils.lookup("java:/Mail"); } catch (IllegalStateException ise) { if (ise.getCause() instanceof NamingException) { LOG.warn("Naming exception. Expected for unit tests only!: " + ise, ise); return null; } throw ise; } }
From source file:de.teammartens.android.wattfinder.worker.AnimationWorker.java
public static void hide_fragment(String FLAG) { fragmentManager.popBackStack(FLAG, 0); Fragment f = fragmentManager.findFragmentByTag(FLAG); if (f != null && f.isVisible()) { try {/*from w w w.jav a 2s . c om*/ fragmentManager.beginTransaction().setCustomAnimations(R.anim.fragment_slide_in, R.anim.fragment_slide_out, R.anim.fragment_slide_in, R.anim.fragment_slide_out).hide(f) .commit(); } catch (IllegalStateException e) { if (LogWorker.isVERBOSE()) LogWorker.e(LOG_TAG, "IllegalSTatException on hide " + FLAG + " " + e.getCause().getMessage()); } //slideDown(getInstance().findViewById(R.id.fab_directions), 0); //slideDown(getInstance().findViewById(R.id.fab_directions), 500); //slideUp(getInstance().findViewById(R.id.fab_filter), 200); //slideUp(getInstance().findViewById(R.id.fab_mylocation), 200); KartenActivity.setMapPaddingY(0); show_fabs(); } //getInstance().findViewById(R.id.fab_filter).setVisibility(View.VISIBLE); //getInstance().findViewById(R.id.fab_mylocation).setVisibility(View.VISIBLE); //getInstance().findViewById(R.id.fab_directions).setVisibility(View.GONE); }
From source file:cherry.foundation.etl.ExtractorImpl.java
/** * ?/*from w w w . jav a 2 s .co m*/ * * @param dataSource * @param sql SQL * @param paramMap ? * @param consumer ?? * @param limiter ? * @return ???? * @throws LimiterException ?? * @throws IOException ? */ @Override public long extract(DataSource dataSource, String sql, Map<String, ?> paramMap, Consumer consumer, Limiter limiter) throws LimiterException, IOException { NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource); ResultSetExtractor<Long> extractor = new ExtractorResultSetExtractor(consumer, limiter); limiter.start(); try { return template.query(sql, paramMap, extractor); } catch (IllegalStateException ex) { throw (IOException) ex.getCause(); } finally { limiter.stop(); } }
From source file:org.sonar.api.utils.PathUtilsTest.java
@Test public void canonicalPath_fails_to_get_canonical_path() throws Exception { File file = mock(File.class); when(file.getCanonicalPath()).thenThrow(new IOException()); try {//from w ww. j av a 2s. co m PathUtils.canonicalPath(file); fail(); } catch (IllegalStateException e) { assertThat(e.getCause()).isInstanceOf(IOException.class); } }
From source file:cherry.foundation.download.DownloadTemplateTest.java
@Test public void testDownload01() throws IOException { HttpServletResponse response = createMock(); LocalDateTime timestamp = LocalDateTime.now(); String ts = DateTimeFormat.forPattern("yyyyMMddHHmmss").print(timestamp); final IOException ioex = new IOException(); DownloadAction action = new DownloadAction() { @Override// www . java2 s . c o m public long doDownload(OutputStream stream) throws IOException { throw ioex; } }; try { downloadOperation.download(response, "text/csv", StandardCharsets.UTF_8, "test_{0}.csv", timestamp, action); fail("Excption must be thrown"); } catch (IllegalStateException ex) { assertSame(ex.getCause(), ioex); } verify(response).setContentType("text/csv"); verify(response).setCharacterEncoding("UTF-8"); verify(response).setHeader("Content-Disposition", "attachment; filename=\"test_" + ts + ".csv\""); }
From source file:org.sonar.api.utils.System2Test.java
@Test public void close_throws_exception_on_error() { Closeable closeable = new Closeable() { @Override//w ww.j a v a 2 s .c o m public void close() throws IOException { throw new IOException("expected"); } }; try { System2.INSTANCE.close(closeable); fail(); } catch (IllegalStateException e) { assertThat(e.getCause().getMessage()).isEqualTo("expected"); } }
From source file:org.apache.ofbiz.entity.transaction.TransactionUtil.java
/** Makes a rollback the only possible outcome of the transaction in the current thread IF transactions are available */ public static void setRollbackOnly(String causeMessage, Throwable causeThrowable) throws GenericTransactionException { UserTransaction ut = TransactionFactoryLoader.getInstance().getUserTransaction(); if (ut != null) { try {/*from w ww .j a v a 2s. co m*/ int status = ut.getStatus(); Debug.logVerbose("Current code : " + getTransactionStateString(status), module); if (status != STATUS_NO_TRANSACTION) { if (status != STATUS_MARKED_ROLLBACK) { if (Debug.warningOn()) { Debug.logWarning(new Exception(causeMessage), "Calling transaction setRollbackOnly; this stack trace shows where this is happening:", module); } ut.setRollbackOnly(); setSetRollbackOnlyCause(causeMessage, causeThrowable); } else { Debug.logInfo("Transaction rollback only not set, rollback only is already set.", module); } } else { Debug.logWarning("Transaction rollback only not set, status is STATUS_NO_TRANSACTION", module); } } catch (IllegalStateException e) { Throwable t = e.getCause() == null ? e : e.getCause(); throw new GenericTransactionException( "Could not set rollback only on transaction, IllegalStateException exception: " + t.toString(), t); } catch (SystemException e) { Throwable t = e.getCause() == null ? e : e.getCause(); throw new GenericTransactionException( "System error, could not set rollback only on transaction: " + t.toString(), t); } } else { Debug.logInfo("No UserTransaction, transaction rollback only not set", module); } }
From source file:org.apache.camel.dataformat.csv.CsvIteratorTest.java
@Test public void closeIfError(@Injectable final InputStreamReader reader, @Injectable final CSVParser parser) throws IOException { new Expectations() { {/*from w w w .ja va 2 s. c o m*/ parser.getLine(); result = new String[] { "1" }; parser.getLine(); result = new String[] { "2" }; parser.getLine(); result = new IOException(HDD_CRASH); // The reader will be closed when there is nothing left reader.close(); } }; @SuppressWarnings("resource") CsvIterator<List<String>> iterator = new CsvIterator<List<String>>(parser, reader, CsvLineConverters.getListConverter()); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(Arrays.asList("1"), iterator.next()); Assert.assertTrue(iterator.hasNext()); try { iterator.next(); Assert.fail("exception expected"); } catch (IllegalStateException e) { Assert.assertEquals(HDD_CRASH, e.getCause().getMessage()); } Assert.assertFalse(iterator.hasNext()); try { iterator.next(); Assert.fail("exception expected"); } catch (NoSuchElementException e) { // okay } }
From source file:org.apache.ofbiz.entity.transaction.TransactionUtil.java
/** Rolls back transaction in the current thread IF transactions are available */ public static void rollback(Throwable causeThrowable) throws GenericTransactionException { UserTransaction ut = TransactionFactoryLoader.getInstance().getUserTransaction(); if (ut != null) { try {//from w w w. j ava2s . c om int status = ut.getStatus(); Debug.logVerbose("Current status : " + getTransactionStateString(status), module); if (status != STATUS_NO_TRANSACTION) { //if (Debug.infoOn()) Thread.dumpStack(); if (causeThrowable == null && Debug.infoOn()) { Exception newE = new Exception("Stack Trace"); Debug.logError(newE, "[TransactionUtil.rollback]", module); } // clear out the stamps to keep it clean clearTransactionStamps(); // clear out the stack too clearTransactionBeginStack(); clearSetRollbackOnlyCause(); ut.rollback(); Debug.logInfo("Transaction rolled back", module); } else { Debug.logWarning("Transaction not rolled back, status is STATUS_NO_TRANSACTION", module); } } catch (IllegalStateException e) { Throwable t = e.getCause() == null ? e : e.getCause(); throw new GenericTransactionException( "Could not rollback transaction, IllegalStateException exception: " + t.toString(), t); } catch (SystemException e) { Throwable t = e.getCause() == null ? e : e.getCause(); throw new GenericTransactionException( "System error, could not rollback transaction: " + t.toString(), t); } } else { Debug.logInfo("No UserTransaction, transaction not rolled back", module); } }
From source file:cherry.foundation.querydsl.QueryDslSupportImpl.java
private long downloadMain(QueryConfigurer commonClause, QueryConfigurer orderByClause, Consumer consumer, Limiter limiter, Expression<?>... expressions) throws LimiterException, IOException { ResultSetExtractor<Long> extractor = new ExtractorResultSetExtractor(consumer, limiter); limiter.start();//from w w w. j a va 2 s . c om try { SQLQuery query = queryDslJdbcOperations.newSqlQuery(); query = commonClause.configure(query); query = orderByClause.configure(query); return queryDslJdbcOperations.queryForObject(query, extractor, expressions); } catch (IllegalStateException ex) { throw (IOException) ex.getCause(); } finally { limiter.stop(); } }