List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:Pool.java
public static <T extends Cloneable> Pool<T> create(T origin, int poolMax) { if (origin == null) { throw new IllegalArgumentException("origin: " + origin); }//from w w w . ja va2s .co m if (poolMax < 1) { throw new IllegalArgumentException("poolMax: " + poolMax); } List<T> copies = new ArrayList<T>(); for (int i = 0; i < poolMax; i++) { try { @SuppressWarnings("unchecked") T copied = (T) origin.getClass().getMethod("clone").invoke(origin); copies.add(copied); } catch (Exception e) { throw new IllegalStateException(e); } } return new Pool<T>(copies); }
From source file:com.amalto.core.history.accessor.RootAccessor.java
public String get() { throw new IllegalStateException("Cannot get value"); }
From source file:com.milaboratory.core.sequence.Alphabets.java
/** * Register new alphabet//ww w . j av a2s. c o m * * @param alphabet alphabet */ public static void register(Alphabet alphabet) { if (alphabetsByName.put(alphabet.getAlphabetName(), alphabet) != null) throw new IllegalStateException("Alphabet with this name is already registered."); if (alphabetsById.put(alphabet.getId(), alphabet) != null) throw new IllegalStateException("Alphabet with this id is already registered."); }
From source file:com.github.sarxos.xchange.impl.FetchOpenExchangeImpl.java
private static HttpUriRequest buildRequest() { Object apikey = System.getProperty(KEY); if (apikey == null) { apikey = ExchangeCache.getParameter(KEY); if (apikey == null) { throw new IllegalStateException("API key has not been found under " + KEY + " parameter"); }/*from w w w .j a v a 2 s .com*/ } URI uri = null; try { uri = new URIBuilder().setScheme("http").setHost(HOST).setPath(ENDPOINT) .setParameter("app_id", apikey.toString()).build(); } catch (URISyntaxException e) { throw new IllegalStateException("Ooops, the URI string seems to be wrong!", e); } LOG.debug("New URI crafted {}", uri); return new HttpGet(uri); }
From source file:amqp.spring.camel.component.SpringAMQPComponentTest.java
@Test public void testFindRootCause() throws Exception { IllegalStateException child = new IllegalStateException("Child Exception"); RuntimeException parent = new RuntimeException("Parent Exception", child); RuntimeException grandparent = new RuntimeException("Grandparent Exception", parent); Assert.assertEquals(child, SpringAMQPComponent.findRootCause(grandparent)); }
From source file:org.seedstack.spring.internal.SeedDataSourceFactoryBean.java
@Override public DataSource getObject() throws Exception { if (name == null) { throw new IllegalArgumentException("Property name is required for SeedDataSourceFactoryBean"); } else {//from w w w . ja va2s. c o m DataSource dataSource = jdbcProvider.getDataSource(name); if (dataSource == null) { throw new IllegalStateException("Unable to find SeedStack data source named " + name); } return dataSource; } }
From source file:com.canoo.webtest.util.WebtestEmbeddingUtil.java
/** * Copies WebTest resources (ie webtest.xml, tools/*, the XSLs, CSSs and pictures, ...) package in WebTest jar file * into the provide folder. Indeed different Ant tasks can't work with resources in a jar file. * @param targetFolder the folder in which resources should be copied to * @throws java.io.IOException if the resources can be accessed or copied */// w w w . jav a 2 s .c o m static void copyWebTestResources(final File targetFolder) throws IOException { final String resourcesPrefix = "com/canoo/webtest/resources/"; final URL webtestXmlUrl = WebtestEmbeddingUtil.class.getClassLoader() .getResource(resourcesPrefix + "webtest.xml"); if (webtestXmlUrl == null) { throw new IllegalStateException("Can't find resource " + resourcesPrefix + "webtest.xml"); } else if (webtestXmlUrl.toString().startsWith("jar:file")) { final String urlJarFileName = webtestXmlUrl.toString().replaceFirst("^jar:file:([^\\!]*).*$", "$1"); final String jarFileName = URLDecoder.decode(urlJarFileName, Charset.defaultCharset().name()); final JarFile jarFile = new JarFile(jarFileName); final String urlPrefix = StringUtils.removeEnd(webtestXmlUrl.toString(), "webtest.xml"); for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { final JarEntry jarEntry = entries.nextElement(); if (jarEntry.getName().startsWith(resourcesPrefix)) { final String relativeName = StringUtils.removeStart(jarEntry.getName(), resourcesPrefix); final URL url = new URL(urlPrefix + relativeName); final File targetFile = new File(targetFolder, relativeName); FileUtils.forceMkdir(targetFile.getParentFile()); FileUtils.copyURLToFile(url, targetFile); } } } else if (webtestXmlUrl.toString().startsWith("file:")) { // we're probably developing and/or have a custom version of the resources in classpath final File webtestXmlFile = FileUtils.toFile(webtestXmlUrl); final File resourceFolder = webtestXmlFile.getParentFile(); FileUtils.copyDirectory(resourceFolder, targetFolder); } else { throw new IllegalStateException( "Resource " + resourcesPrefix + "webtest.xml is not in a jar file: " + webtestXmlUrl); } }
From source file:Main.java
public static Document readXml(File xmlFile) throws IllegalArgumentException { try {/*from w w w . j a v a2 s . com*/ Document document = newDocumentBuilder().parse(xmlFile); document.setXmlStandalone(true); return document; } catch (IOException e) { throw new IllegalArgumentException(e); } catch (SAXException e) { throw new IllegalArgumentException(e); } catch (ParserConfigurationException e) { throw new IllegalStateException(e); } }
From source file:com.intel.podm.client.RetryInvoker.java
public static <T, U extends RedfishApiException> T retry(SupplierWithRedfishException<T, U> supplier) throws U { Exception lastException;// w ww. ja v a 2 s .c om int currentAttempt = 1; do { try { return supplier.get(); } catch (Exception e) { if (isNotConnectionException(e) || maximumAttemptsReached(currentAttempt)) { throw e; } sleep(currentAttempt); lastException = e; currentAttempt++; } } while (currentAttempt <= MAX_RETRY_ATTEMPTS); throw new IllegalStateException(lastException); }
From source file:gridool.discovery.DiscoveryServiceProvider.java
@Nonnull public static GridDiscoveryService createService(@Nonnull GridResourceRegistry resourceRegistry, @Nonnull GridConfiguration config) { final GridDiscoveryService srv; final String serviceType = Settings.get("gridool.discovery"); if ("jgroups".equals(serviceType)) { srv = new JGroupsDiscoveryService(resourceRegistry, config); } else if ("file".equals(serviceType)) { srv = new FileDiscoveryService(config); } else {/*from w ww .ja v a2s . c om*/ throw new IllegalStateException( "Unexpected service type is set for 'gridool.discovery': " + serviceType); } GridRouter router = resourceRegistry.getRouter(); srv.addListener(router); ReplicationManager replMgr = resourceRegistry.getReplicationManager(); ReplicaCoordinator replCoord = replMgr.getReplicaCoordinator(); srv.addListener(replCoord); // TODO REVIEWME String additional = Settings.get("gridool.discovery.listener"); if (additional != null) { setupAdditionalListeners(srv, additional); } resourceRegistry.setDiscoveryService(srv); return srv; }