Search in sources :

Example 11 with RuntimeException

use of java.lang.RuntimeException in project camunda-bpm-platform by camunda.

the class TestConnector method execute.

public TestConnectorResponse execute(TestConnectorRequest req) {
    // capture request parameters
    requestParameters = req.getRequestParameters();
    TestRequestInvocation testRequestInvocation = new TestRequestInvocation(null, req, requestInterceptors);
    try {
        testRequestInvocation.proceed();
        // use response parameters
        return new TestConnectorResponse(responseParameters);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RuntimeException(java.lang.RuntimeException) RuntimeException(java.lang.RuntimeException) Exception(java.lang.Exception)

Example 12 with RuntimeException

use of java.lang.RuntimeException in project sugar by satyan.

the class QueryBuilder method generatePlaceholders.

public static String generatePlaceholders(int numberOfArgs) {
    if (numberOfArgs < 1) {
        throw new RuntimeException("The number of arguments must be greater than or equal to 1.");
    }
    StringBuilder stringBuilder = new StringBuilder(numberOfArgs * 2 - 1);
    stringBuilder.append("?");
    for (int i = 1; i < numberOfArgs; i++) {
        stringBuilder.append(",?");
    }
    return stringBuilder.toString();
}
Also used : RuntimeException(java.lang.RuntimeException) StringBuilder(java.lang.StringBuilder)

Example 13 with RuntimeException

use of java.lang.RuntimeException in project lucene-solr by apache.

the class TestWindowsFS method testOpenDeleteConcurrently.

public void testOpenDeleteConcurrently() throws IOException, Exception {
    final Path dir = wrap(createTempDir());
    final Path file = dir.resolve("thefile");
    final CyclicBarrier barrier = new CyclicBarrier(2);
    final AtomicBoolean stopped = new AtomicBoolean(false);
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                barrier.await();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
            while (stopped.get() == false) {
                try {
                    if (random().nextBoolean()) {
                        Files.delete(file);
                    } else if (random().nextBoolean()) {
                        Files.deleteIfExists(file);
                    } else {
                        Path target = file.resolveSibling("other");
                        Files.move(file, target);
                        Files.delete(target);
                    }
                } catch (IOException ex) {
                // continue
                }
            }
        }
    };
    t.start();
    barrier.await();
    try {
        final int iters = 10 + random().nextInt(100);
        for (int i = 0; i < iters; i++) {
            boolean opened = false;
            try (OutputStream stream = Files.newOutputStream(file)) {
                opened = true;
                stream.write(0);
            // just create
            } catch (FileNotFoundException | NoSuchFileException ex) {
                assertEquals("File handle leaked - file is closed but still registered", 0, ((WindowsFS) dir.getFileSystem().provider()).openFiles.size());
                assertFalse("caught FNF on close", opened);
            }
            assertEquals("File handle leaked - file is closed but still registered", 0, ((WindowsFS) dir.getFileSystem().provider()).openFiles.size());
            Files.deleteIfExists(file);
        }
    } finally {
        stopped.set(true);
        t.join();
    }
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) RuntimeException(java.lang.RuntimeException) FileNotFoundException(java.io.FileNotFoundException) Exception(java.lang.Exception) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RuntimeException(java.lang.RuntimeException) WindowsFS(org.apache.lucene.mockfile.WindowsFS)

Example 14 with RuntimeException

use of java.lang.RuntimeException in project jdk8u_jdk by JetBrains.

the class CipherInputStreamExceptions method cbc_shortStream.

/* Check that close() does not throw an exception with full message in
     * CipherInputStream's ibuffer.
     * This test:
     *   1) Encrypts a 97 byte message with AES/CBC/PKCS5Padding
     *   2) Create a stream that sends 96 bytes.
     *   3) Read stream once,
     *   4) Close and expect no exception
     */
static void cbc_shortStream() throws Exception {
    Cipher c;
    AlgorithmParameters params;
    byte[] read = new byte[200];
    System.out.println("Running cbc_shortStream");
    // Encrypt 97 byte with AES/CBC/PKCS5Padding
    byte[] ct = encryptedText("CBC", 97);
    // Create stream with only 96 bytes of encrypted data
    CipherInputStream in = getStream("CBC", ct, 96);
    try {
        int size = in.read(read);
        in.close();
        if (size != 80) {
            throw new RuntimeException("Fail: CipherInputStream.read() " + "returned " + size + ". Should have been 80");
        }
        System.out.println("  Pass.");
    } catch (IOException e) {
        System.out.println("  Fail:  " + e.getMessage());
        throw new RuntimeException(e.getCause());
    }
}
Also used : RuntimeException(java.lang.RuntimeException) CipherInputStream(javax.crypto.CipherInputStream) Cipher(javax.crypto.Cipher) IOException(java.io.IOException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 15 with RuntimeException

use of java.lang.RuntimeException in project jdk8u_jdk by JetBrains.

the class CipherInputStreamExceptions method cbc_readAllIllegalBlockSize.

/* Check that exception is thrown when message is fully read
     * This test:
     *   1) Encrypts a 96 byte message with AES/CBC/PKCS5Padding
     *   2) Create a stream that sends 95 bytes.
     *   3) Read stream to the end
     *   4) Expect IllegalBlockSizeException thrown
     */
static void cbc_readAllIllegalBlockSize() throws Exception {
    byte[] read = new byte[200];
    System.out.println("Running cbc_readAllIllegalBlockSize test");
    // Encrypt 96 byte with AES/CBC/PKCS5Padding
    byte[] ct = encryptedText("CBC", 96);
    // Create a stream with only 95 bytes of encrypted data
    CipherInputStream in = getStream("CBC", ct, 95);
    try {
        int s, size = 0;
        while ((s = in.read(read)) != -1) {
            size += s;
        }
        throw new RuntimeException("Fail: No IllegalBlockSizeException. " + "CipherInputStream.read() returned " + size);
    } catch (IOException e) {
        Throwable ec = e.getCause();
        if (ec instanceof IllegalBlockSizeException) {
            System.out.println("  Pass.");
        } else {
            System.out.println("  Fail: " + ec.getMessage());
            throw new RuntimeException(ec);
        }
    }
}
Also used : RuntimeException(java.lang.RuntimeException) CipherInputStream(javax.crypto.CipherInputStream) Throwable(java.lang.Throwable) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) IOException(java.io.IOException)

Aggregations

RuntimeException (java.lang.RuntimeException)23 IOException (java.io.IOException)11 CipherInputStream (javax.crypto.CipherInputStream)9 WebElement (org.openqa.selenium.WebElement)7 Hashtable (java.util.Hashtable)4 Cipher (javax.crypto.Cipher)4 File (java.io.File)3 Exception (java.lang.Exception)3 Throwable (java.lang.Throwable)3 AEADBadTagException (javax.crypto.AEADBadTagException)3 Test (org.junit.Test)3 FileNotFoundException (java.io.FileNotFoundException)2 Boolean (java.lang.Boolean)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 SearchContext (org.openqa.selenium.SearchContext)2 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)2 SuppressLint (android.annotation.SuppressLint)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 TransactionTooLargeException (android.os.TransactionTooLargeException)1 BufferedReader (java.io.BufferedReader)1