Example usage for java.lang IllegalStateException IllegalStateException

List of usage examples for java.lang IllegalStateException IllegalStateException

Introduction

In this page you can find the example usage for java.lang IllegalStateException IllegalStateException.

Prototype

public IllegalStateException(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:com.vmware.identity.interop.FileSystemPathLocator.java

public static String getCacheFolderPath() {
    String cacheDirPath = null;//from w  w w  .  j  a  v a  2 s . c o m

    if (SystemUtils.IS_OS_WINDOWS) {
        cacheDirPath = Shell32Util.getFolderPath(ShlObj.CSIDL_LOCAL_APPDATA);
    } else {
        cacheDirPath = LINUX_CACHE_FOLDER_ROOT;
    }

    if (cacheDirPath == null || cacheDirPath.isEmpty()) {
        throw new IllegalStateException("Found empty cache dir path");
    }

    return String.format("%s%s%s%s%s", cacheDirPath, SystemUtils.FILE_SEPARATOR, VMWARE_FOLDER_NAME,
            SystemUtils.FILE_SEPARATOR, VMWARE_IDENTITY_FOLDER_NAME);
}

From source file:Main.java

/**
 * Returns an empty document to which nodes can be appended.
 * @return an empty document to which nodes can be appended.
 *///from   w ww.  ja  v a2s  .  c o m
public static Document getEmptyDoc() {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);

    try {
        return factory.newDocumentBuilder().newDocument();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e); // shouldn't be reached
    }

}

From source file:demo.utils.MiniClusterUtils.java

public static void startMiniCluster() {
    if (clusterLauncher != null) {
        throw new IllegalStateException("MiniClustrer is currently running");
    }/*  w  ww .  j av  a  2 s .  co  m*/
    File file = new File(System.getProperty("user.dir"));
    Path path = Paths.get(file.getAbsolutePath());
    Path parentPath = path.getParent();
    String[] resources = file.list();
    for (String resource : resources) {
        if (resource.equals("yaya-demo")) {
            parentPath = path;
            break;
        }
    }
    File miniClusterExe = new File(
            parentPath.toString() + "/yarn-test-cluster/build/install/yarn-test-cluster/bin/yarn-test-cluster");
    System.out.println(miniClusterExe.getAbsolutePath());
    if (!miniClusterExe.exists()) {
        logger.info("BUILDING MINI_CLUSTER");
        CommandProcessLauncher buildLauncher = new CommandProcessLauncher(
                path.toString() + "/build-mini-cluster");
        buildLauncher.launch();
    }
    Assert.isTrue(miniClusterExe.exists(), "Failed to find mini-cluster executable");
    clusterLauncher = new CommandProcessLauncher(miniClusterExe.getAbsolutePath());
    executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            logger.info("STARTING MINI_CLUSTER");
            clusterLauncher.launch();
        }
    });
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}

From source file:io.liveoak.testtools.AbstractTestCase.java

@BeforeClass
public static void setupMongo() throws IOException {
    if (mongoLauncher != null) {
        throw new IllegalStateException("Assertion failed: static mongoLauncher is not null");
    }//from  ww w.j  a  va  2 s.c  om
    String host = System.getProperty("mongo.host");
    String port = System.getProperty("mongo.port");
    String moduleDir = System.getProperty("user.dir");

    if (host != null && ("localhost".equals(host) || "127.0.0.1".equals(host))) {

        // make sure mongod is installed
        String mongodPath = MongoInstaller.autoInstall();

        if (mongodPath == null) {
            throw new RuntimeException("Failed to install MongoDB!");
        }

        // launch mongod
        mongoLauncher = new MongoLauncher();
        mongoLauncher.setMongodPath(mongodPath);
        mongoLauncher.setUseSmallFiles(true);

        if (port != null) {
            mongoPort = Integer.parseInt(port);
        }
        mongoLauncher.setPort(mongoPort);

        if (host != null) {
            mongoHost = host;
        }
        mongoLauncher.setHost(mongoHost);

        String dataDir = new File(moduleDir, "target/data_" + randomName()).getAbsolutePath();
        File ddFile = new File(dataDir);
        if (!ddFile.isDirectory()) {
            if (!ddFile.mkdirs()) {
                throw new RuntimeException("Failed to create a data directory: " + dataDir);
            }
        }
        String logFile = new File(dataDir, "mongod.log").getAbsolutePath();
        mongoLauncher.setDbPath(dataDir);
        mongoLauncher.setLogPath(logFile);
        mongoLauncher.setPidFilePath(new File(ddFile, "mongod.pid").getAbsolutePath());
        mongoLauncher.startMongo();

        // wait for it to start
        long start = System.currentTimeMillis();
        while (!mongoLauncher.serverRunning(mongoHost, mongoPort, (e) -> {
            if (System.currentTimeMillis() - start > 120000)
                throw new RuntimeException(e);
        })) {
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                throw new RuntimeException("Interrupted!");
            }
        }
    }
}

From source file:Main.java

public static NodeList getNodes(String expression, Node root) {
    XPath xpath = xPathFactory.newXPath();
    try {//from  w  w  w.j  a  v  a  2s  .  c  o  m
        NodeList list = (NodeList) xpath.evaluate(expression, root, XPathConstants.NODESET);
        return list;
    } catch (XPathExpressionException xpe) {
        throw new IllegalStateException(xpe);
    }
}

From source file:Main.java

public static Document readXml(InputStream inputStream) {
    try {/*  ww w  .  ja  v a2  s  . c o m*/
        Document document = newDocumentBuilder().parse(inputStream);
        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:Main.java

/** Check if a number is palindromic. */
public static boolean isPalindrome(BigInteger num) {
    String digits = num.toString();
    int numDigits = digits.length();
    if (numDigits >= MAX_DIGITS) {
        throw new IllegalStateException("too big");
    }/*from  w w w.  ja  v a 2  s  .c  o m*/
    // Consider any single digit to be as palindromic as can be
    if (numDigits == 1)
        return true;
    for (int i = 0; i < numDigits / 2; i++) {
        // System.out.println(
        //    digits.charAt(i) + " ? " + digits.charAt(numDigits - i - 1));
        if (digits.charAt(i) != digits.charAt(numDigits - i - 1))
            return false;
    }
    return true;
}

From source file:com.jdom.junit.utils.TestUtil.java

/**
 * Setup the directory the test class should use.
 * //from   ww  w.jav  a2  s . c o  m
 * @param testClass
 *            The test class to create a directory for
 * @return The directory created for the test class
 */
public static File setupTestClassDir(Class<?> testClass) {
    File dir = new File(System.getProperty("java.io.tmpdir"), testClass.getSimpleName());

    // Delete any preexisting version
    try {
        FileUtils.deleteDirectory(dir);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    // Make the directory
    dir.mkdirs();

    return dir;
}

From source file:org.trustedanalytics.cloud.cc.api.CcLastOperationType.java

@JsonCreator
public static CcLastOperationType create(String value) {
    return Arrays.asList(CcLastOperationType.values()).stream().filter(enm -> enm.type.equalsIgnoreCase(value))
            .findFirst().orElseThrow(() -> new IllegalStateException(
                    String.format("Unable to deserialize %s from %s", CcLastOperationType.class, value)));
}

From source file:Main.java

/**
 * Atomically subtracts a value from the requested amount unless it's at Long.MAX_VALUE.
 * @param requested the requested amount holder
 * @param n the value to subtract from the requested amount, has to be positive (not verified)
 * @return the new requested amount//from  www  .j av a2 s  .c o  m
 * @throws IllegalStateException if n is greater than the current requested amount, which
 * indicates a bug in the request accounting logic
 */
public static long produced(AtomicLong requested, long n) {
    for (;;) {
        long current = requested.get();
        if (current == Long.MAX_VALUE) {
            return Long.MAX_VALUE;
        }
        long next = current - n;
        if (next < 0L) {
            throw new IllegalStateException("More produced than requested: " + next);
        }
        if (requested.compareAndSet(current, next)) {
            return next;
        }
    }
}