Example usage for java.lang RuntimeException getCause

List of usage examples for java.lang RuntimeException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.rackspacecloud.blueflood.io.serializers.SerializationTest.java

@Test(expected = SerializationException.class)
public void testCannotRoundtripBytesWillNullType() throws Throwable {
    try {/*from   w ww  .j a v a2  s  . c  o  m*/
        byte[] expected = new byte[] { 1, 2, 3, 4, 5 };
        ColumnFamily<Locator, Long> CF = null;
        ByteBuffer bb = NumericSerializer.serializerFor((Class) null).toByteBuffer(expected);
        byte[] actual = (byte[]) NumericSerializer.serializerFor((Class) null).fromByteBuffer(bb);
        Assert.assertArrayEquals(expected, actual);
    } catch (RuntimeException ex) {
        throw ex.getCause();
    }
}

From source file:org.obiba.opal.shell.commands.ImportCommand.java

private void runtimeExceptionHandler(RuntimeException ex) {
    log.error("Runtime error while importing data", ex);
    if (ex.getCause() != null && ex.getCause() instanceof NonExistentVariableEntitiesException) {
        getShell().printf(/*  ww  w .j av  a 2  s  . c om*/
                "Datasource '%s' cannot be imported 'as-is'. It contains the following entity ids which are not present "
                        + "as public identifiers in the keys database. %s\n",
                options.getSource(),
                ((NonExistentVariableEntitiesException) ex.getCause()).getNonExistentIdentifiers());
    } else {
        printThrowable(ex, true, 0);
    }
}

From source file:org.wildfly.security.tool.CredentialStoreCommandTest.java

@Test
public void testAliasesList() {
    String storageLocation = getStoragePathForNewFile();
    String storagePassword = "cspassword";
    String[] aliasNames = { "testalias1", "testalias2", "testalias3" };
    String[] aliasValues = { "secret1", "secret2", "secret3" };

    for (int i = 0; i < aliasNames.length; i++) {
        try {/*from  w  ww . ja  v  a  2 s  .  co m*/
            createStoreAndAddAliasAndCheck(storageLocation, storagePassword, aliasNames[i], aliasValues[i]);
        } catch (RuntimeException e) {
            if (!(e.getCause() instanceof NullPointerException)) {
                Assert.fail("It must fail because of there is forbidden to use empty alias name or value.");
            }
        }
    }

    String[] args = new String[] { "--location=" + storageLocation, "--create", "--aliases", "--summary",
            "--password", storagePassword, "--properties", "keyStoreType=JCEKS;keyAlias=not_relevant" };
    executeCommandAndCheckStatus(args);

    String output = executeCommandAndCheckStatusAndGetOutput(args);
    assertTrue(output.startsWith("Credential store contains following aliases:"));
    for (String aliasName : aliasNames) {
        if (!output.contains(aliasName)) {
            Assert.fail(String.format("Credential store must contain aliasName [%s]. But output is [%s].",
                    aliasName, output));
        }
    }
}

From source file:org.amplafi.flow.web.bindings.FlowPropertyBinding.java

protected Object getFlowStateProperty(Class<?> expected) {
    Object result = null;//from   w  w  w  .  j a  v a  2s  . c  o  m
    // Determine if there is a flow state to get the value from, if not just return defaultValue
    FlowState flowState = getFlowState();
    LapTimer.sLap("FlowPropertyBinding: Getting property ", key);
    if (flowState != null) {
        addValidation(flowState.getCurrentActivity(), cycle.renderStackPeek());
        try {
            result = flowState.getProperty(key, expected);
        } catch (RuntimeException e) {
            if (e.getCause() instanceof ValidatorException) {
                throw new BindingException(e.getMessage(), this, e.getCause());
            } else {
                throw new BindingException(e.getMessage(), this, e);
            }
        }
    }
    LapTimer.sLap("FlowPropertyBinding: Got property ", key);
    if (result == null && defaultValueBinding != null) {
        result = defaultValueBinding.getObject(expected);
    }
    return result;
}

From source file:org.kramerius.replications.SecondPhase.java

public void ingest(File foxmlfile) throws PhaseException {
    LOGGER.info("ingesting '" + foxmlfile.getAbsolutePath() + "'");
    Import.initialize(KConfiguration.getInstance().getProperty("ingest.user"),
            KConfiguration.getInstance().getProperty("ingest.password"));
    try {//w  w  w  . j ava  2  s. c  o  m
        Import.ingest(foxmlfile, null, null, null, false); //TODO tet parametr m bt List<String>, inicializovan na za?tku tto fze a pedan tet fzi, kde se budou tdit vazby
    } catch (RuntimeException e) {
        if (e.getCause() != null)
            throw new PhaseException(this, e.getCause());
        else
            throw new PhaseException(this, e);
    }
}

From source file:com.glaf.core.db.mybatis2.SqlMapClientFactoryBean.java

/**
 * Build a SqlMapClient instance based on the given standard configuration.
 * <p>/* w  w  w.  j av a 2  s . c  om*/
 * The default implementation uses the standard iBATIS
 * {@link SqlMapClientBuilder} API to build a SqlMapClient instance based on
 * an InputStream (if possible, on iBATIS 2.3 and higher) or on a Reader (on
 * iBATIS up to version 2.2).
 * 
 * @param configLocations
 *            the config files to load from
 * @param properties
 *            the SqlMapClient properties (if any)
 * @return the SqlMapClient instance (never {@code null})
 * @throws IOException
 *             if loading the config file failed
 * @see com.ibatis.sqlmap.client.SqlMapClientBuilder#buildSqlMapClient
 */
protected SqlMapClient buildSqlMapClient(Resource[] configLocations, Resource[] mappingLocations,
        Properties properties) throws IOException {

    if (ObjectUtils.isEmpty(configLocations)) {
        throw new IllegalArgumentException("At least 1 'configLocation' entry is required");
    }

    SqlMapClient client = null;
    SqlMapConfigParser configParser = new SqlMapConfigParser();
    for (Resource configLocation : configLocations) {
        InputStream is = configLocation.getInputStream();
        try {
            client = configParser.parse(is, properties);
        } catch (RuntimeException ex) {
            throw new NestedIOException("Failed to parse config resource: " + configLocation, ex.getCause());
        }
    }

    if (mappingLocations != null) {
        SqlMapParser mapParser = SqlMapParserFactory.createSqlMapParser(configParser);
        for (Resource mappingLocation : mappingLocations) {
            try {
                mapParser.parse(mappingLocation.getInputStream());
            } catch (NodeletException ex) {
                throw new NestedIOException("Failed to parse mapping resource: " + mappingLocation, ex);
            }
        }
    }

    return client;
}

From source file:com.rackspacecloud.blueflood.io.serializers.SerializationTest.java

@Test
public void testBadSerializationVersion() {
    byte[] buf = new byte[] { 99, 99 }; // hopefully we won't have 99 different serialization versions.
    for (Class type : SERIALIZABLE_TYPES) {
        try {//  w w w .  j  av a  2s .c  o  m
            Object o = NumericSerializer.serializerFor(type).fromByteBuffer(ByteBuffer.wrap(buf));
            Assert.fail(String.format("Should have errored out %s", type.getName()));
        } catch (RuntimeException ex) {
            Assert.assertTrue(ex.getCause().getMessage().startsWith("Unexpected serialization version"));
        }
    }
}

From source file:org.geoserver.importer.bdb.BDBImportStore.java

void checkAndFixDbIncompatability(DatabaseConfig dbConfig, Environment env) {
    // check for potential class incompatibilities and attempt recovery
    try {//ww w  .  ja v a2  s .c  o m
        ImportContext context = iterator().next();
        System.out.println(context);
    } catch (RuntimeException re) {
        if (re.getCause() instanceof java.io.ObjectStreamException) {
            LOGGER.warning("Unable to read import database, attempting recovery");

            // wipe out the catalog
            dbBinding.closeDb(env);
            dbBinding.destroyDb(env);

            // and the import db
            db.close();
            env.removeDatabase(null, "imports");

            // reopen
            initDb(dbConfig, env);
        }
    }

}

From source file:com.rackspacecloud.blueflood.io.SerializationTest.java

@Test
public void testFullResSerializationAndDeserialization() throws IOException {
    // if the GENERATE_SERIALIZATION flag is set, save everything.
    if (System.getProperty("GENERATE_FULL_RES_SERIALIZATION") != null) {
        OutputStream os = new FileOutputStream(
                "src/test/resources/serializations/full_version_" + Constants.VERSION_1_FULL_RES + ".bin",
                false);// w  ww  .j  a  va2 s . co m
        for (Object o : toSerializeFull) {
            // encode as base64 to make reading the file easier.

            os.write(Base64.encodeBase64(NumericSerializer.get(Granularity.FULL).toByteBuffer(o).array()));
            os.write("\n".getBytes());
        }
        os.close();
    }

    Assert.assertTrue(new File("src/test/resources/serializations").exists());

    // ensure we can read historical serializations.
    int version = 0; // versions before this are illegal.
    int maxVersion = Constants.VERSION_1_FULL_RES;
    while (version <= maxVersion) {
        BufferedReader reader = new BufferedReader(
                new FileReader("src/test/resources/serializations/full_version_" + version + ".bin"));
        for (int i = 0; i < toSerializeFull.length; i++)
            try {
                // we used to allow deserializing strings, but we don't anymore.
                // catch that error and assert it happens only when expected.
                ByteBuffer byteBuffer = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes()));
                Assert.assertEquals(String.format("broken at version %d", version),
                        NumericSerializer.get(Granularity.FULL).fromByteBuffer(byteBuffer), toSerializeFull[i]);
            } catch (RuntimeException ex) {
                Assert.assertEquals(ex.getCause().getClass(), UnexpectedStringSerializationException.class);
                Assert.assertEquals(3, i);
                Assert.assertTrue(toSerializeFull[i] instanceof String);
            }
        version += 1;
    }

    // ensure that current round-tripping isn't broken.
    for (Object o : toSerializeFull) {
        // skip the string (we used to allow this).
        if (o instanceof String)
            continue; // we don't serialize those any more.
        ByteBuffer serialized = NumericSerializer.get(Granularity.FULL).toByteBuffer(o);
        Assert.assertEquals(o, NumericSerializer.get(Granularity.FULL).fromByteBuffer(serialized));
    }
}

From source file:com.healthmarketscience.jackcess.complex.ComplexColumnInfo.java

public void deleteAllValues(int complexValueFk) throws IOException {
    Iterator<Map<String, Object>> entryIter = getComplexValFkIter(complexValueFk,
            Collections.<String>emptySet());
    try {//from w  w  w  .  j ava 2  s .  c om
        while (entryIter.hasNext()) {
            entryIter.next();
            entryIter.remove();
        }
    } catch (RuntimeException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
        throw e;
    }
}