List of usage examples for java.lang ClassCastException getCause
public synchronized Throwable getCause()
From source file:com.rackspacecloud.blueflood.io.SerializationTest.java
@Test public void testFullResRoundTrip() throws IOException { // tests serialization of all types that should be handled, including granularity variations. Object[] inputs = { 7565, 323234234235223321L, 213432.53323d, 42332.0234375f, toSerializeRollup[0], toSerializeRollup[1], toSerializeRollup[2], toSerializeRollup[3] }; Object[] expected = { 7565, 323234234235223321L, 213432.53323d, 42332.0234375d, // notice that serialization converts to a double. toSerializeRollup[0], toSerializeRollup[1], toSerializeRollup[2], toSerializeRollup[3] }; for (Granularity gran : Granularity.granularities()) { for (int i = 0; i < inputs.length; i++) { try { Object dst = NumericSerializer.get(gran) .fromByteBuffer(NumericSerializer.get(gran).toByteBuffer(inputs[i])); Assert.assertEquals(String.format("busted at %s %d", gran.name(), i), expected[i], dst); } catch (ClassCastException ex) { ex.printStackTrace();// w w w.ja va 2 s . c o m Assert.fail("Serialization should address class type mismatches as IOExceptions"); } catch (RuntimeException ex) { Assert.assertTrue(ex.getCause() instanceof SerializationException); if (gran == Granularity.FULL) Assert.assertTrue(inputs[i] instanceof Rollup); else Assert.assertFalse(inputs[i] instanceof Rollup); } catch (Throwable unexpected) { unexpected.printStackTrace(); Assert.fail(String.format("Unexpected error at %s %d", gran.name(), i)); } } } }
From source file:com.rackspacecloud.blueflood.io.serializers.SerializationTest.java
@Test public void testFullResRoundTrip() throws IOException { // tests serialization of all types that should be handled, including granularity variations. Object[] inputs = { 7565, 323234234235223321L, 213432.53323d, 42332.0234375f, TO_SERIALIZE_BASIC_ROLLUP[0], TO_SERIALIZE_BASIC_ROLLUP[1], TO_SERIALIZE_BASIC_ROLLUP[2], TO_SERIALIZE_BASIC_ROLLUP[3] }; Object[] expected = { 7565, 323234234235223321L, 213432.53323d, 42332.0234375d, // notice that serialization converts to a double. TO_SERIALIZE_BASIC_ROLLUP[0], TO_SERIALIZE_BASIC_ROLLUP[1], TO_SERIALIZE_BASIC_ROLLUP[2], TO_SERIALIZE_BASIC_ROLLUP[3] }; for (Class type : SERIALIZABLE_TYPES) { for (int i = 0; i < inputs.length; i++) { try { Object dst = NumericSerializer.serializerFor(type) .fromByteBuffer(NumericSerializer.serializerFor(type).toByteBuffer(inputs[i])); Assert.assertEquals(String.format("busted at %s %d", type.getName(), i), expected[i], dst); } catch (ClassCastException ex) { // these are expected because of the various types. // todo: this test could be made better by // 1) having one iteration to verify that we can serialize for matched types. // 2) having various other tests that verify that serialization breaks in expected ways when // types are mismatched continue; } catch (RuntimeException ex) { if (ex.getCause() == null) throw ex; Assert.assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof SerializationException); if (inputs[i] instanceof BasicRollup) Assert.assertFalse(type.equals(BasicRollup.class)); else Assert.assertTrue(type.equals(BasicRollup.class)); } catch (Throwable unexpected) { unexpected.printStackTrace(); Assert.fail(String.format("Unexpected error at %s %d", type.getName(), i)); }// ww w . ja v a 2 s . co m } } }
From source file:org.apache.metron.stellar.common.StellarPredicateProcessor.java
@Override public Boolean parse(String rule, VariableResolver variableResolver, FunctionResolver functionResolver, Context context) {//from w w w.jav a 2 s .co m if (rule == null || isEmpty(rule.trim())) { return true; } try { return super.parse(rule, variableResolver, functionResolver, context); } catch (ClassCastException e) { // predicate must return boolean throw new IllegalArgumentException( String.format("The rule '%s' does not return a boolean value.", rule), e); } catch (Exception e) { if (e.getCause() != null && e.getCause() instanceof ClassCastException) { throw new IllegalArgumentException( String.format("The rule '%s' does not return a boolean value.", rule), e.getCause()); } throw e; } }
From source file:org.neo4j.server.rest.web.CypherService.java
@POST @SuppressWarnings({ "unchecked", "ParameterCanBeLocal" }) public Response cypher(String body, @Context HttpServletRequest request, @QueryParam(INCLUDE_STATS_PARAM) boolean includeStats, @QueryParam(INCLUDE_PLAN_PARAM) boolean includePlan, @QueryParam(PROFILE_PARAM) boolean profile) throws BadInputException { Map<String, Object> command = input.readMap(body); if (!command.containsKey(QUERY_KEY)) { return output.badRequest(new BadInputException("You have to provide the 'query' parameter.")); }/* w ww. j a v a 2 s .c o m*/ String query = (String) command.get(QUERY_KEY); Map<String, Object> params; try { params = (Map<String, Object>) (command.containsKey(PARAMS_KEY) && command.get(PARAMS_KEY) != null ? command.get(PARAMS_KEY) : new HashMap<String, Object>()); } catch (ClassCastException e) { return output.badRequest(new IllegalArgumentException("Parameters must be a JSON map")); } try { QueryExecutionEngine executionEngine = cypherExecutor.getExecutionEngine(); boolean periodicCommitQuery = executionEngine.isPeriodicCommit(query); CommitOnSuccessfulStatusCodeRepresentationWriteHandler handler = (CommitOnSuccessfulStatusCodeRepresentationWriteHandler) this.output .getRepresentationWriteHandler(); if (periodicCommitQuery) { handler.closeTransaction(); } Result result; if (profile) { result = executionEngine.profileQuery(query, params, new ServerQuerySession(request)); includePlan = true; } else { result = executionEngine.executeQuery(query, params, new ServerQuerySession(request)); includePlan = result.getQueryExecutionType().requestedExecutionPlanDescription(); } if (periodicCommitQuery) { handler.setTransaction(database.beginTx()); } return output.ok(new CypherResultRepresentation(result, includeStats, includePlan)); } catch (Throwable e) { if (e.getCause() instanceof CypherException) { return output.badRequest(e.getCause()); } else { return output.badRequest(e); } } }
From source file:pt.webdetails.cda.cache.HazelcastQueryCache.java
@Override public TableModel getTableModel(TableCacheKey key) { try {//from ww w .j a v a 2s . co m ExtraCacheInfo info = getWithTimeout(key, getCacheStats()); if (info != null) { //per instance ttl not supported by hazelcast, need to check manually if (info.getTimeToLive() > 0 && (info.getTimeToLive() + info.getEntryTime()) < System.currentTimeMillis()) { logger.info("Cache element expired, removing from cache."); getCache().removeAsync(key); return null; } else { TableModel tm = getWithTimeout(key, getCache()); if (tm == null) { logger.error("Cache stats out of sync! Removing element."); getCacheStats().removeAsync(key); return null; } logger.info("Table found in cache. Returning."); return tm; } } return null; } catch (ClassCastException e) { //handle issue when map would return a dataRecordEntry instead of element type //TODO: hasn't been caught in a while, maybe we can drop this Object obj = getCache().get(key); logger.error("Expected TableModel in cache, found " + obj.getClass().getCanonicalName() + " instead."); if (obj instanceof DataRecordEntry) { DataRecordEntry drEntry = (DataRecordEntry) obj; logger.info("Cache holding DataRecordEntry, attempting recovery"); Object val = drEntry.getValue(); if (val instanceof TableModel) { TableModel tm = (TableModel) val; logger.warn("TableModel found in record, attempting to replace cache entry.."); getCache().replace(key, tm); logger.info("Cache entry replaced."); return tm; } else { logger.error("DataRecordEntry in cache has value of unexpected type " + obj.getClass().getCanonicalName()); logger.warn("Removing incompatible cache entry."); getCache().remove(key); } } return null; } catch (Exception e) { if (e.getCause() instanceof IOException) {//most likely a StreamCorruptedException logger.error("IO error while attempting to get key " + key + "(" + e.getCause().getMessage() + "), removing from cache!", e); getCache().removeAsync(key); return null; } else logger.error("Unexpected exception ", e); return null; } }