List of usage examples for java.lang IllegalArgumentException getCause
public synchronized Throwable getCause()
From source file:org.apache.hadoop.hive.metastore.security.DBTokenStore.java
private Object invokeOnTokenStore(String methName, Object[] params, Class<?>... paramTypes) throws TokenStoreException { Object tokenStore;/*from ww w. j a v a 2 s . c o m*/ try { switch (serverMode) { case METASTORE: tokenStore = handler.getClass().getMethod("getMS").invoke(handler); break; case HIVESERVER2: Object hiveObject = ((Class<?>) handler).getMethod("get").invoke(handler, null); tokenStore = ((Class<?>) handler).getMethod("getMSC").invoke(hiveObject); break; default: throw new IllegalArgumentException("Unexpected value of Server mode " + serverMode); } return tokenStore.getClass().getMethod(methName, paramTypes).invoke(tokenStore, params); } catch (IllegalArgumentException e) { throw new TokenStoreException(e); } catch (SecurityException e) { throw new TokenStoreException(e); } catch (IllegalAccessException e) { throw new TokenStoreException(e); } catch (InvocationTargetException e) { throw new TokenStoreException(e.getCause()); } catch (NoSuchMethodException e) { throw new TokenStoreException(e); } }
From source file:org.vosao.rest.RestManager.java
private String runService(String serviceKey, List<String> path, Map<String, String> params) throws Throwable { Object restService = services.get(serviceKey); if (restService != null) { // check Authorized if (restService.getClass().getAnnotation(Authorized.class) != null) { if (VosaoContext.getInstance().getUser() == null) { throw new AuthenticationException("User is not authenticated."); }// w w w . j a va 2s . co m } MatchResult result = matchMethod(restService, path, params); if (result != null) { try { // check Authorized if (result.method.getAnnotation(Authorized.class) != null) { if (VosaoContext.getInstance().getUser() == null) { throw new AuthenticationException("User is not authenticated."); } } Object invokeResult = result.method.invoke(restService, result.args); if (invokeResult instanceof String) return (String) invokeResult; else return new JSONObject(invokeResult).toString(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { if (e.getCause() != null) throw e.getCause(); e.printStackTrace(); } } } return null; }
From source file:org.apache.hadoop.hive.thrift.DBTokenStore.java
private Object invokeOnTokenStore(String methName, Object[] params, Class<?>... paramTypes) throws TokenStoreException { Object tokenStore;/*from ww w. j a v a2s . c o m*/ try { switch (smode) { case METASTORE: tokenStore = handler.getClass().getMethod("getMS").invoke(handler); break; case HIVESERVER2: Object hiveObject = ((Class<?>) handler) .getMethod("get", org.apache.hadoop.conf.Configuration.class, java.lang.Class.class) .invoke(handler, conf, DBTokenStore.class); tokenStore = ((Class<?>) handler).getMethod("getMSC").invoke(hiveObject); break; default: throw new TokenStoreException(new Exception("unknown server mode")); } return tokenStore.getClass().getMethod(methName, paramTypes).invoke(tokenStore, params); } catch (IllegalArgumentException e) { throw new TokenStoreException(e); } catch (SecurityException e) { throw new TokenStoreException(e); } catch (IllegalAccessException e) { throw new TokenStoreException(e); } catch (InvocationTargetException e) { throw new TokenStoreException(e.getCause()); } catch (NoSuchMethodException e) { throw new TokenStoreException(e); } }
From source file:org.sakaiproject.genericdao.hibernate.CompleteGenericDaoTest.java
/** * Test method for {@link org.sakaiproject.genericdao.hibernate.HibernateCompleteGenericDao#deleteSet(java.util.Set)}. *//* w ww.j a v a 2 s .c om*/ @Test public void testDeleteSet() { Set<GenericTestObject> deleteSet = new HashSet<GenericTestObject>(); deleteSet.add(gto1); deleteSet.add(gto2); genericDao.deleteSet(deleteSet); List<GenericTestObject> l = genericDao.findAll(GenericTestObject.class); Assert.assertNotNull(l); Assert.assertEquals(3, l.size()); Assert.assertTrue(!l.contains(gto1)); Assert.assertTrue(!l.contains(gto2)); // Now try to cause various Exceptions // test no longer needed // Set<GenericTestObject> deleteFailSet = new HashSet<GenericTestObject>(); // deleteFailSet.add(gto4); // deleteFailSet.add("string"); // non-matching object type // try { // genericDao.deleteSet(deleteFailSet); // Assert.fail("Should have thrown an exception before getting here"); // } catch (IllegalArgumentException e) { // Assert.assertNotNull(e); // } catch (Exception e) { // Assert.fail("Threw wrong exception: ("+e.getCause()+"): " + e.getMessage()); // } // // l = genericDao.findAll(GenericTestObject.class); // Assert.assertNotNull(l); // Assert.assertEquals(3, l.size()); // Assert.assertTrue(l.contains(gto4)); Set<String> deleteFailSet = new HashSet<String>(); deleteFailSet.add("string"); // non-persistent object type try { genericDao.deleteSet(deleteFailSet); Assert.fail("Should have thrown an exception before getting here"); } catch (IllegalArgumentException e) { Assert.assertNotNull(e); } catch (Exception e) { Assert.fail("Threw wrong exception: (" + e.getCause() + "): " + e.getMessage()); } l = genericDao.findAll(GenericTestObject.class); Assert.assertNotNull(l); Assert.assertEquals(3, l.size()); Assert.assertTrue(l.contains(gto4)); // had to remove this test because it depends on order -AZ // GenericTestObject gto = new GenericTestObject("title", Boolean.TRUE); // deleteFailSet = new HashSet(); // // I don't like that order is important for this test to work... -AZ // deleteFailSet.add(gto); // object is not in the DB // deleteFailSet.add(gto4); // try { // genericDao.deleteSet(deleteFailSet); // Assert.fail("Should have thrown an exception before getting here"); // } catch (InvalidDataAccessApiUsageException e) { // Assert.assertNotNull(e); // } catch (Exception e) { // Assert.fail("Threw wrong exception: ("+e.getCause()+"): " + e.getMessage()); // } // // l = genericDao.findAll(GenericTestObject.class); // Assert.assertNotNull(l); // Assert.assertEquals(3, l.size()); // Assert.assertTrue(l.contains(gto4)); }
From source file:com.sworddance.beans.PropertyAdaptor.java
/** * Updates the property of the target object. * @param <T>//from ww w . j a v a2s . co m * * @param target the object to update * @param value the value to be stored into the target object property * @return value returned by the set operation ( usually void ) */ @SuppressWarnings("unchecked") public <T> T write(Object target, Object value) { if (setter == null) { throw new ApplicationGeneralException("No set" + this.propertyName + "()"); } else { try { return (T) setter.invoke(target, new Object[] { value }); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(setter.toGenericString(), e); } catch (IllegalAccessException e) { throw new IllegalArgumentException(setter.toGenericString(), e); } catch (InvocationTargetException e) { throw new IllegalArgumentException(setter.toGenericString(), e.getCause()); } } }
From source file:it.geosolutions.geobatch.actions.freemarker.FreeMarkerAction.java
/** * Removes TemplateModelEvents from the queue and put *//*from w w w. ja v a 2 s . com*/ public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { listenerForwarder.started(); listenerForwarder.setTask("initializing the FreeMarker engine"); if (!initialized) { try { initialize(); } catch (IllegalArgumentException e) { throw new ActionException(this, e.getLocalizedMessage(), e.getCause()); } catch (IOException e) { throw new ActionException(this, e.getLocalizedMessage(), e.getCause()); } } listenerForwarder.setTask("build the output absolute file name"); // build the output absolute file name File outputDir = computeOutputDir(); // may throw ActionEx // return final Queue<EventObject> ret = new LinkedList<EventObject>(); listenerForwarder.setTask("Building/getting the root data structure"); /* * Building/getting the root data structure */ final Map<String, Object> root = conf.getRoot() != null ? conf.getRoot() : new HashMap<String, Object>(); // list of incoming event to inject into the root datamodel final List<TemplateModel> list; if (conf.isNtoN()) { list = new ArrayList<TemplateModel>(events.size()); } else { list = new ArrayList<TemplateModel>(1); } // append the list of adapted event objects root.put(TemplateModelEvent.EVENT_KEY, list); while (!events.isEmpty()) { // the adapted event final TemplateModelEvent ev; final TemplateModel dataModel; try { if ((ev = adapter(events.remove())) != null) { listenerForwarder.setTask("Try to get a Template DataModel from the Adapted event"); // try to get a Template DataModel from the Adapted event dataModel = ev.getModel(processor); } else { final String message = "Unable to append the event: unrecognized format. SKIPPING..."; if (LOGGER.isErrorEnabled()) { LOGGER.error(message); } if (conf.isFailIgnored()) { continue; } else { final ActionException e = new ActionException(this, message); listenerForwarder.failed(e); throw e; } } } catch (TemplateModelException tme) { final String message = "Unable to wrap the passed object: " + tme.getLocalizedMessage(); if (LOGGER.isErrorEnabled()) LOGGER.error(message); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(tme); throw new ActionException(this, tme.getLocalizedMessage()); } } catch (Exception ioe) { final String message = "Unable to produce the output: " + ioe.getLocalizedMessage(); if (LOGGER.isErrorEnabled()) LOGGER.error(message); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(ioe); throw new ActionException(this, ioe.getLocalizedMessage(), ioe); } } listenerForwarder.setTask("Generating the output"); /* * If getNtoN: For each data incoming event (Template DataModel) * build a file. Otherwise the entire queue of incoming object will * be transformed in a list of datamodel. In this case only one file * is generated. */ if (conf.isNtoN()) { if (list.size() > 0) { list.remove(0); } list.add(dataModel); final File outputFile; // append the incoming data structure try { outputFile = buildOutput(outputDir, root); } catch (ActionException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e.getLocalizedMessage(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw e; } } // add the file to the return ret.add(new FileSystemEvent(outputFile.getAbsoluteFile(), FileSystemEventType.FILE_ADDED)); } else { list.add(dataModel); } } if (!conf.isNtoN()) { final File outputFile; // append the incoming data structure try { outputFile = buildOutput(outputDir, root); } catch (ActionException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e.getLocalizedMessage(), e); listenerForwarder.failed(e); throw e; } // add the file to the return ret.add(new FileSystemEvent(outputFile.getAbsoluteFile(), FileSystemEventType.FILE_ADDED)); } listenerForwarder.completed(); return ret; }
From source file:org.evosuite.testcase.FieldReference.java
/** * {@inheritDoc}//from www . j a v a 2s .c om * * Return the actual object represented by this variable for a given scope */ @Override public Object getObject(Scope scope) throws CodeUnderTestException { Object s; if (field.isStatic()) { s = null; } else { s = source.getObject(scope); } try { return field.getField().get(s); } catch (IllegalArgumentException e) { logger.debug("Error accessing field {} of object {}: {}", field, source, e, e); throw new CodeUnderTestException(e.getCause()); } catch (IllegalAccessException e) { logger.error("Error accessing field {} of object {}: {}", field, source, e, e); throw new EvosuiteError(e); } catch (NullPointerException e) { throw new CodeUnderTestException(e); } catch (ExceptionInInitializerError e) { throw new CodeUnderTestException(e); } }
From source file:org.getobjects.appserver.publisher.GoJavaMethod.java
public Object callInContext(final Object _object, final IGoContext _ctx) { if (this.method == null) { log.error("GoJavaMethod has not Method: " + this); return new GoInternalErrorException("GoJavaMethod has no method?"); }//from w ww . j av a 2 s . co m if (_object == null) { // Objective-C semantics ;-) log.info("calling GoMethod on null (noop): " + this); return null; } // TODO: implement me // TODO: implement parameter handling Object[] args = this.argumentsForMethodCallInContext(_object, _ctx); Object result = null; try { result = this.method.invoke(_object, args); } catch (IllegalArgumentException e) { result = e; log.error("Invalid argument on Java method on object: " + _object, e); } catch (IllegalAccessException e) { result = e; log.error("Cannot access Java method on object: " + _object, e); } catch (InvocationTargetException e) { result = e.getCause(); log.error("Invocation target error on method with object: " + _object, e.getCause()); } return result; }
From source file:org.apache.hadoop.hbase.master.ZKClusterStateRecovery.java
/** * Register live regionservers that we read from ZK with ServerManager. We do this after starting * RPC threads but before log splitting. *//*from w w w . j a v a 2s. co m*/ void registerLiveRegionServers() throws IOException { liveRSNamesAtStartup = zkw.getLiveRSNames(); liveRSNamesAtStartupUnmodifiable = Collections.unmodifiableSet(liveRSNamesAtStartup); Set<String> rsNamesToAdd = new TreeSet<String>(liveRSNamesAtStartup); boolean needToSleep = false; // no need to sleep at the first iteration while (!rsNamesToAdd.isEmpty()) { if (needToSleep) { Threads.sleepRetainInterrupt(HConstants.SOCKET_RETRY_WAIT_MS); } // We cannot modify rsNamesToAdd as we iterate it, so we add RS names to retry to this list. Set<String> rsLeftToAdd = new TreeSet<String>(); for (String rsName : rsNamesToAdd) { if (master.isStopped()) { throw new IOException("Master is shutting down"); } if (Thread.interrupted()) { throw new IOException("Interrupted when scanning live RS directory in ZK"); } HServerInfo serverInfo; try { serverInfo = HServerInfo.fromServerName(rsName); } catch (IllegalArgumentException ex) { // This error is probably not going to fix itself automatically. Exit the retry loop. throw new IOException("Read invalid server name for live RS directory in ZK: " + rsName, ex); } try { serverManager.recordNewServer(serverInfo); } catch (IOException ex) { if (ex.getCause() instanceof NoNodeException) { // This regionserver has disappeared, don't try to register it. This will also ensure // that we split the logs for this regionserver as part of initial log splitting. LOG.info("Regionserver znode " + rsName + " disappeared, not registering"); liveRSNamesAtStartup.remove(rsName); } else { LOG.error("Error recording a new regionserver: " + serverInfo.getServerName() + ", will retry", ex); rsLeftToAdd.add(rsName); } } } rsNamesToAdd = rsLeftToAdd; needToSleep = true; // will sleep before the re-trying } }