List of usage examples for java.lang ClassCastException getMessage
public String getMessage()
From source file:illab.nabal.proxy.TwitterContext.java
/** * Restore session data from persistent storage. * /*from w w w. ja va2s . co m*/ * @return true if successfully restored from persistent storage * @throws Exception */ protected boolean restoreSession() throws Exception { // no need to restore session if this session is covert op if (mIsCovertOp == true) { return false; } // restore session synchronized (mAccessToken) { if (StringHelper.isEmpty(mAlias) == false) { Log.i(TAG, "trying to restore session data from storage" + " for agent " + mAlias + " ..."); } else { Log.i(TAG, "trying to restore session data from storage..."); } try { // get a map from shared preferences file stored in persistent storage Map<String, String> map = getPrefMap(); for (String key : map.keySet()) { // assign values to variables read from storage String value = (String) map.get(key); if (OAUTH_TOKEN.equals(key) == true) { mAccessToken = value; } else if (OAUTH_TOKEN_SECRET.equals(key) == true) { mAccessTokenSecret = value; } else if (USER_ID.equals(key) == true) { mUserId = value; } else if (SCREEN_NAME.equals(key) == true) { mScreenName = value; } } // check integrity if (StringHelper.isAllFull(mAccessToken, mAccessTokenSecret, mUserId, mScreenName) == true) { Log.i(TAG, "successfully restored session data."); Log.i(TAG, "###############################"); Log.i(TAG, "mAccessToken : " + mAccessToken); Log.i(TAG, "mAccessTokenSecret : " + mAccessTokenSecret); Log.i(TAG, "mUserId : " + mUserId); Log.i(TAG, "mScreenName : " + mScreenName); Log.i(TAG, "###############################"); return true; } } catch (ClassCastException e) { Log.e(TAG, e.getMessage()); } // make sure empty session data if failed to restore Log.i(TAG, "failed to restore session data."); purgeSession(); return false; } }
From source file:nl.strohalm.cyclos.utils.access.PermissionsDescriptor.java
private Collection<? extends Element> resolveMembers(Object argument) { if (argument == null) { throw new IllegalArgumentException("Can not resolve related members: null argument"); }/*from ww w. j a va 2s. com*/ final PathToMember pathToMember = getPathToMember(); final RelatedEntity relatedEntity = getRelatedEntity(); if (pathToMember == null) { throw new IllegalStateException("The " + this + " has no @PathToMember annotation"); } // Coerce from String to Long if (argument instanceof String) { argument = CoercionHelper.coerce(Long.class, argument); } else if (argument instanceof String[]) { argument = CoercionHelper.coerce(Long[].class, argument); } // Resolve the objects to search for members Object[] objects; if (argument instanceof Long || argument instanceof Long[]) { if (relatedEntity == null) { throw new IllegalStateException("The " + this + " has no @RelatedEntity annotation"); } final Class<? extends Entity> entityType = relatedEntity.value(); if (argument instanceof Long) { objects = new Object[] { EntityHelper.reference(entityType, (Long) argument) }; } else { final Long[] ids = (Long[]) argument; objects = new Object[ids.length]; for (int i = 0; i < ids.length; i++) { final Long id = ids[i]; objects[i] = EntityHelper.reference(entityType, id); } } } else { objects = CoercionHelper.coerce(Object[].class, argument); } // Get the paths to members final String[] paths = pathToMember.value(); for (int i = 0; i < paths.length; i++) { paths[i] = StringUtils.trimToNull(paths[i]); } final List<Element> members = new ArrayList<Element>(); for (final Object object : objects) { for (final String path : paths) { try { final Element member = fetchMember(object, path); // if (member == null) { // throw new IllegalStateException("The '" + path + "' property on argument '" + object + "' for method " + method + " was null"); // } // members.add(member); if (member != null) { members.add(member); } } catch (final ClassCastException e) { throw new IllegalStateException("The '" + path + "' property on argument '" + object + "' for " + this + " was not a member, but a '" + e.getMessage() + "'"); } } } return members; }
From source file:org.asqatasun.processing.ProcessRemarkServiceImpl.java
@Override public void addCssCodeRemark(TestSolution processResult, String selectorValue, String messageCode, String attrName, String fileName) {// XXX SourceCodeRemark remark = processRemarkDataService.getSourceCodeRemark(processResult, messageCode); // This a fake sourceCode Remark, the line number cannot be found // we use a sourceCodeRemark here to add evidence elements remark.setLineNumber(-1);// w ww.j a v a 2 s .c o m EvidenceElement evidenceElement = evidenceElementDataService.getEvidenceElement(remark, attrName, getEvidence(DEFAULT_EVIDENCE)); remark.addElement(evidenceElement); try { if (selectorValue != null) { EvidenceElement cssSelectorEvidenceElement = evidenceElementDataService.getEvidenceElement(remark, selectorValue, getEvidence(CSS_SELECTOR_EVIDENCE)); remark.addElement(cssSelectorEvidenceElement); } if (fileName != null) { EvidenceElement fileNameEvidenceElement = evidenceElementDataService.getEvidenceElement(remark, fileName, getEvidence(CSS_FILENAME_EVIDENCE)); remark.addElement(fileNameEvidenceElement); } } catch (ClassCastException ex) { LOGGER.error(ex.getMessage()); } remarkSet.add(remark); }
From source file:org.xmlactions.action.config.ExecContext.java
public String getAction(String actionMapName, String actionKey) { String className = null;/*from w w w . j a va 2 s . c om*/ Map<String, Object> map; try { if (actionMapName == null) { map = actionMaps.get(DEFAULT_ACTION_MAP); } else { map = actionMaps.get(actionMapName); if (map == null) { return getAction(null, actionKey); } } if (map != null) { className = (String) map.get(actionKey); if (StringUtils.isEmpty(className)) { if (StringUtils.isNotEmpty(actionMapName)) { return getAction(null, actionKey); } } } return className; } catch (ClassCastException ex) { throw new IllegalArgumentException( ex.getMessage() + " - actionMapName[" + actionMapName + "] actionKey [" + actionKey + "]", ex); } }
From source file:com.github.cherimojava.data.mongo.io._DeEncoding.java
@Test public void implicitIdTypeVerification() { try {//from w ww. j a v a 2 s .co m factory.create(ReferencingEntity.class).set(ID, "one"); fail("should throw an exception"); } catch (ClassCastException e) { assertThat(e.getMessage(), allOf(containsString("ObjectId"), containsString("String"))); } }
From source file:org.apache.geode.management.internal.cli.commands.DestroyRegionCommand.java
private Set<DistributedMember> findMembersForRegion(InternalCache cache, ManagementService managementService, String regionPath) {//w w w .j a va 2 s .c om Set<DistributedMember> membersList = new HashSet<>(); Set<String> regionMemberIds = new HashSet<>(); MBeanServer mbeanServer = MBeanJMXAdapter.mbeanServer; // needs to be escaped with quotes if it contains a hyphen if (regionPath.contains("-")) { regionPath = "\"" + regionPath + "\""; } String queryExp = MessageFormat.format(MBeanJMXAdapter.OBJECTNAME__REGION_MXBEAN, regionPath, "*"); try { ObjectName queryExpON = new ObjectName(queryExp); Set<ObjectName> queryNames = mbeanServer.queryNames(null, queryExpON); if (queryNames == null || queryNames.isEmpty()) { return membersList; // protects against null pointer exception below } boolean addedOneRemote = false; for (ObjectName regionMBeanObjectName : queryNames) { try { RegionMXBean regionMXBean = managementService.getMBeanInstance(regionMBeanObjectName, RegionMXBean.class); if (regionMXBean != null) { RegionAttributesData regionAttributes = regionMXBean.listRegionAttributes(); String scope = regionAttributes.getScope(); // For Scope.LOCAL regions we need to identify each hosting member, but for // other scopes we just need a single member as the region destroy will be // propagated. if (Scope.LOCAL.equals(Scope.fromString(scope))) { regionMemberIds.add(regionMXBean.getMember()); } else { if (!addedOneRemote) { regionMemberIds.add(regionMXBean.getMember()); addedOneRemote = true; } } } } catch (ClassCastException e) { LogWriter logger = cache.getLogger(); if (logger.finerEnabled()) { logger.finer(regionMBeanObjectName + " is not a " + RegionMXBean.class.getSimpleName(), e); } } } if (!regionMemberIds.isEmpty()) { membersList = getMembersByIds(cache, regionMemberIds); } } catch (MalformedObjectNameException | NullPointerException e) { LogWrapper.getInstance().info(e.getMessage(), e); } return membersList; }
From source file:org.thbz.hanguldrill.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main_activity_actions, menu); try {/* w w w . j ava 2 s. c o m*/ MenuItem configListItem = menu.findItem(R.id.action_configlist); String[] configIds = Settings.ConfigManager.getAllConfigIds(this); if (configListItem.hasSubMenu() && configIds.length > 0) { SubMenu configMenu = configListItem.getSubMenu(); if (configMenu == null) { if (BuildConfig.DEBUG) Log.d(TAG, "configMenu = null"); } else { // On ajoute une entre pour chacune des configurations existantes for (int i = 0; i < configIds.length; i++) { String configId = configIds[i]; Settings.Configuration config = Settings.ConfigManager.getConfigFromId(this, configId); String name = config.getName(this); configMenu.add(Menu.NONE, START_MENUITEM_ID + i, i, name); } } // Set configMenu title try { Settings.Configuration lastSelectedConfig = Settings.ConfigManager.getLastSelectedConfig(this); if (lastSelectedConfig != null) { String configName = lastSelectedConfig.getName(this); if (configName != null) { if (configName.length() > 15) configName = configName.substring(0, 13) + "\u2026"; configListItem.setTitle(configName); } } } catch (ClassCastException exc) { toastError("Exception : " + exc.getMessage()); } } } catch (InternalException exc) { if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Log.e(TAG, "Erreur interne", exc); } return super.onCreateOptionsMenu(menu); }
From source file:org.opens.tanaguru.processing.ProcessRemarkServiceImpl.java
@Override public void addCssCodeRemark(TestSolution processResult, String selectorValue, String messageCode, String attrName, String fileName) {// XXX SourceCodeRemark remark = sourceCodeRemarkFactory.create(); remark.setIssue(processResult);// ww w. java2 s.co m remark.setMessageCode(messageCode); // This a fake sourceCode Remark, the line number cannot be found // we use a sourceCodeRemark here to add evidence elements remark.setLineNumber(-1); EvidenceElement evidenceElement = evidenceElementFactory.create(); evidenceElement.setProcessRemark(remark); evidenceElement.setValue(attrName); evidenceElement.setEvidence(getEvidence(DEFAULT_EVIDENCE)); remark.addElement(evidenceElement); try { if (selectorValue != null) { EvidenceElement cssSelectorEvidenceElement = evidenceElementFactory.create(); cssSelectorEvidenceElement.setProcessRemark(remark); cssSelectorEvidenceElement.setValue(selectorValue); cssSelectorEvidenceElement.setEvidence(getEvidence(CSS_SELECTOR_EVIDENCE)); remark.addElement(cssSelectorEvidenceElement); } if (fileName != null) { EvidenceElement fileNameEvidenceElement = evidenceElementFactory.create(); fileNameEvidenceElement.setProcessRemark(remark); fileNameEvidenceElement.setValue(fileName); fileNameEvidenceElement.setEvidence(getEvidence(CSS_FILENAME_EVIDENCE)); remark.addElement(fileNameEvidenceElement); } } catch (ClassCastException ex) { LOGGER.error(ex.getMessage()); } remarkSet.add(remark); }
From source file:cx.fbn.nevernote.threads.IndexRunner.java
private void indexResourceRTF(Resource r) { Data d = r.getData();// w w w. j a va 2s . c o m for (int i = 0; i < 20 && d.getSize() == 0; i++) d = r.getData(); if (d.getSize() == 0) return; QTemporaryFile f = writeResource(d); if (!keepRunning) { return; } InputStream input; try { input = new FileInputStream(new File(f.fileName())); ContentHandler textHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); RTFParser parser = new RTFParser(); ParseContext context = new ParseContext(); parser.parse(input, textHandler, metadata, context); String[] result = textHandler.toString().split(regex); for (int i = 0; i < result.length && keepRunning; i++) { addToIndex(r.getNoteGuid(), result[i], "RESOURCE"); } input.close(); f.close(); } catch (java.lang.ClassCastException e) { logger.log(logger.LOW, "Cast exception: " + e.getMessage()); } catch (FileNotFoundException e) { logger.log(logger.LOW, "FileNotFound exception: " + e.getMessage()); } catch (IOException e) { logger.log(logger.LOW, "IO exception: " + e.getMessage()); } catch (SAXException e) { logger.log(logger.LOW, "SAX exception: " + e.getMessage()); } catch (TikaException e) { logger.log(logger.LOW, "Tika exception: " + e.getMessage()); } catch (Exception e) { logger.log(logger.LOW, "Unknown exception: " + e.getMessage()); } catch (java.lang.NoSuchMethodError e) { logger.log(logger.LOW, "NoSuchMethod error: " + e.getMessage()); } catch (Error e) { logger.log(logger.LOW, "Unknown error: " + e.getMessage()); } }
From source file:cx.fbn.nevernote.threads.IndexRunner.java
private void indexResourceODF(Resource r) { Data d = r.getData();/*from ww w . ja v a 2 s. com*/ for (int i = 0; i < 20 && d.getSize() == 0; i++) d = r.getData(); if (d.getSize() == 0) return; QTemporaryFile f = writeResource(d); if (!keepRunning) { return; } InputStream input; try { input = new FileInputStream(new File(f.fileName())); ContentHandler textHandler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); OpenDocumentParser parser = new OpenDocumentParser(); ParseContext context = new ParseContext(); parser.parse(input, textHandler, metadata, context); String[] result = textHandler.toString().split(regex); for (int i = 0; i < result.length && keepRunning; i++) { if (interrupt) { processInterrupt(); } addToIndex(r.getNoteGuid(), result[i], "RESOURCE"); } input.close(); f.close(); } catch (java.lang.ClassCastException e) { logger.log(logger.LOW, "Cast exception: " + e.getMessage()); } catch (FileNotFoundException e) { logger.log(logger.LOW, "FileNotFound exception: " + e.getMessage()); } catch (IOException e) { logger.log(logger.LOW, "IO exception: " + e.getMessage()); } catch (SAXException e) { logger.log(logger.LOW, "SAX exception: " + e.getMessage()); } catch (TikaException e) { logger.log(logger.LOW, "Tika exception: " + e.getMessage()); } catch (Exception e) { logger.log(logger.LOW, "Unknown exception: " + e.getMessage()); } catch (java.lang.NoSuchMethodError e) { logger.log(logger.LOW, "NoSuchMethod error: " + e.getMessage()); } catch (Error e) { logger.log(logger.LOW, "Unknown error: " + e.getMessage()); } }