Example usage for java.lang ClassCastException getMessage

List of usage examples for java.lang ClassCastException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:se.vgregion.dao.domain.patterns.repository.jpa.JpaRepositoryTest.java

@Test
// Tests issue #7
public void shouldCreateInstanceOfGrandChildOfAbstractJpaRepository() throws Exception {
    CarRepo.RaceCarRepo repo = null;/* w  ww.  j av  a2 s . co m*/
    try {
        repo = new CarRepo().new RaceCarRepo();
    } catch (ClassCastException e) {
        fail(e.getMessage());
    }
    assertEquals(repo.getType(), Car.class);
}

From source file:org.apache.hawq.pxf.plugins.hdfs.utilities.RecordkeyAdapterTest.java

/**
 * Test convertKeyValue for boolean type and then string type - negative
 * test/*from w w w  . j  a v  a  2 s  .c o m*/
 */
@Test
public void convertKeyValueBadSecondValue() {
    boolean key = true;
    initRecordkeyAdapter();
    runConvertKeyValue(key, new BooleanWritable(key));
    String badKey = "bad";
    try {
        recordkeyAdapter.convertKeyValue(badKey);
        fail("conversion of string to boolean should fail");
    } catch (ClassCastException e) {
        assertEquals(e.getMessage(), "java.lang.String cannot be cast to java.lang.Boolean");
    }
}

From source file:org.eclipse.jubula.communication.internal.parser.MessageSerializer.java

/**
 * Deserializes a message represented by the passed string with XML content.
 * The message header is used to determine the message class name. So, this
 * property, the header itself and the message string must not be
 * <code>null</code>.// ww  w.  ja va  2s.c  om
 * 
 * @param header
 *            The message header
 * @param message
 *            The XML string to deserialize
 * @return The deserialized message
 * @throws SerialisationException
 *             If the deserialization fails
 */
public Message deserialize(MessageHeader header, String message) throws SerialisationException {

    checkParseParameters(header, message);
    try {
        Class messageClass = Class.forName(header.getMessageClassName());
        return (Message) m_serializer.deserialize(message, messageClass);
    } catch (ClassCastException cce) {
        // messageClass is not of type Message
        throw new SerialisationException(cce.getMessage(), MessageIDs.E_SERILIZATION_FAILED);
    } catch (ClassNotFoundException cnfe) {
        // message class not found
        throw new SerialisationException(cnfe.getMessage(), MessageIDs.E_SERILIZATION_FAILED);
    }
}

From source file:com.orange.mmp.api.ws.jsonrpc.SimpleListSerializer.java

@SuppressWarnings("unchecked")
@Override/*from   w w w.j  av  a 2  s .  c  om*/
public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    List list = null;
    try {
        try {
            try {
                if (clazz.isInterface()) {
                    list = new java.util.ArrayList();
                } else
                    list = (List) clazz.newInstance();
            } catch (ClassCastException cce) {
                throw new UnmarshallException("invalid unmarshalling Class " + cce.getMessage());
            }
        } catch (IllegalAccessException iae) {
            throw new UnmarshallException("no access unmarshalling object " + iae.getMessage());
        }
    } catch (InstantiationException ie) {
        throw new UnmarshallException("unable to instantiate unmarshalling object " + ie.getMessage());
    }
    JSONArray jsa = (JSONArray) o;

    state.setSerialized(o, list);
    int i = 0;
    try {
        for (; i < jsa.length(); i++) {
            list.add(ser.unmarshall(state, null, jsa.get(i)));
        }
    } catch (UnmarshallException e) {
        throw new UnmarshallException("element " + i + " " + e.getMessage());
    } catch (JSONException e) {
        throw new UnmarshallException("element " + i + " " + e.getMessage());
    }
    return list;
}

From source file:org.openadaptor.auxil.expression.function.FormatFn.java

/**
 * Generate a formatted <code>String</code> object from a supplied value
 * /* www. ja  va 2  s .com*/
 * @param args
 *          Object[] which should contain two arguments - the Object to be formatted, and the format to be applied
 *          (typically a <code>String</code>)
 * @return Object containing a <code>String</code> with the formatted value.
 * @throws ExpressionException
 *           If arguments cannot be cast appropriately
 */
protected Object operate(Object[] args) throws ExpressionException {
    try {
        Object arg0 = args[0];
        if (arg0 instanceof Date) { // Format a Date as a String, using the supplied Format.
            return format((Date) arg0, getArgAsString(args[1], ""));
        }
        String badClass = (arg0 == null) ? "<null>" : arg0.getClass().getName();
        throw new ExpressionException("Unable to format " + badClass);

    } catch (ClassCastException cce) {
        throw new ExpressionException("Invalid argument(s) to " + getName() + ". " + cce.getMessage());
    }
}

From source file:com.apress.progwt.server.dao.hibernate.UserDAOHibernateImpl.java

/**
 * use iterate() to avoid returning rows. Hibernate ref "11.13. Tips &
 * Tricks"/*from   w  ww.j  a  va2  s  .  com*/
 * 
 * grrrrr... started throwing a classcastexception, but not
 * repeatable..
 */
public long getUserCount() {
    try {
        return (Long) getHibernateTemplate().iterate("select count(*) from User").next();
    } catch (ClassCastException e) {
        log.error(e.getMessage());
        return 10000;
    }
}

From source file:nl.basvanmarwijk.mylocations.viewcontroller.LocationItemCursorAdapter.java

/**
 * Makes a new view to hold the data pointed to by cursor.
 *
 * @param context Interface to application's global information
 * @param cursor  The cursor from which to get the data. The cursor is already
 *                moved to the correct position.
 * @param parent  The parent to which the new view is attached to
 * @return the newly created view./*from   w w  w. j  a  va  2  s . c o m*/
 */
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    View newView;
    ItemView holder = new ItemView();

    //haal de view op uit xml
    newView = inflater.inflate(R.layout.placeview, parent, false);
    try {
        holder.flag = (ImageView) newView.findViewById(R.id.iv_flag);
        holder.country = (TextView) newView.findViewById(R.id.tvCountry);
        holder.place = (TextView) newView.findViewById(R.id.tvPlace);

        newView.setTag(holder);
    } catch (ClassCastException e) {
        Log.e(TAG, "Could not create view from inflater: " + e.getMessage());
    }

    return newView;
}

From source file:org.springframework.context.event.SimpleApplicationEventMulticaster.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void doInvokeListener(ApplicationListener listener, ApplicationEvent event) {
    try {/*from   w w  w.j a v a  2  s . co m*/
        listener.onApplicationEvent(event);
    } catch (ClassCastException ex) {
        String msg = ex.getMessage();
        if (msg == null || matchesClassCastMessage(msg, event.getClass().getName())) {
            // Possibly a lambda-defined listener which we could not resolve the generic event type for
            // -> let's suppress the exception and just log a debug message.
            Log logger = LogFactory.getLog(getClass());
            if (logger.isDebugEnabled()) {
                logger.debug("Non-matching event type for listener: " + listener, ex);
            }
        } else {
            throw ex;
        }
    }
}

From source file:com.fluidops.iwb.api.CommunicationServiceImpl.java

private static Map<URI, List<Pair<Value, Resource>>> transformResult(TupleQueryResult res, String varPred,
        String varVal, String varSrc) throws Exception {
    try {/* w ww.  ja  va2  s .  co m*/
        Map<URI, List<Pair<Value, Resource>>> result = new HashMap<URI, List<Pair<Value, Resource>>>();
        while (res.hasNext()) {
            try {
                BindingSet bs = res.next();
                Binding val = bs.getBinding(varVal);
                Binding pred = bs.getBinding(varPred);
                Binding src = bs.getBinding(varSrc);

                if (val != null && pred != null && src != null) {
                    URI pVal = (URI) pred.getValue();
                    Value vVal = (Value) val.getValue();
                    Resource srcVal = (Resource) src.getValue();

                    List<Pair<Value, Resource>> inner = result.get(pVal);
                    if (inner == null) {
                        inner = new ArrayList<Pair<Value, Resource>>();
                        result.put(pVal, inner);
                    }

                    inner.add(new Pair<Value, Resource>(vVal, srcVal));
                }
            } catch (ClassCastException e) {
                logger.warn(e.getMessage(), e);
            } catch (Exception e) {
                logger.warn(e.getMessage(), e);
            }
        }
        return result;
    } finally {
        ReadWriteDataManagerImpl.closeQuietly(res);
    }
}

From source file:otsopack.commons.network.coordination.spacemanager.FileSpaceManager.java

@Override
public Node[] getRegisteredNodes() throws SpaceManagerException {
    final Node[] nodes;
    try {//from w  w w .  java 2s.  co m
        final FileInputStream fis = new FileInputStream(this.file);
        final String fileContent = IOUtils.toString(fis);
        ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
        List<Object> arr = mapper.readValue(fileContent, List.class);

        nodes = new Node[arr.size()];
        int i = 0;
        for (Object object : arr) {
            final LinkedHashMap<String, Object> obj = (LinkedHashMap<String, Object>) object;
            final String uuid = (String) obj.get("uuid");
            final String url = (String) obj.get("url");
            final boolean reachable = optBoolean(obj, "reachable", true);
            final boolean isBulletinBoard = optBoolean(obj, "bulletinBoard", true);
            final boolean mustPoll = optBoolean(obj, "mustPoll", false);
            final Node node = new Node(url, uuid, reachable, isBulletinBoard, mustPoll);
            nodes[i] = node;
            i++;
        }
    } catch (ClassCastException e) {
        throw new SpaceManagerException(
                "Error retrieving nodes from file " + this.file.getAbsolutePath() + ":" + e.getMessage(), e);
    } catch (Exception e) {
        throw new SpaceManagerException(
                "Error retrieving nodes from file " + this.file.getAbsolutePath() + ":" + e.getMessage(), e);
    }
    return nodes;
}