List of usage examples for java.lang NoSuchMethodException getCause
public synchronized Throwable getCause()
From source file:com.micmiu.hive.fotmater.Base64TextInputFormat.java
/** * Workaround an incompatible change from commons-codec 1.3 to 1.4. * Since Hadoop has this jar on its classpath, we have no way of knowing * which version we are running against. */// w ww .j av a 2 s . c o m static Base64 createBase64() { try { // This constructor appeared in 1.4 and specifies that we do not want to // line-wrap or use any newline separator Constructor<Base64> ctor = Base64.class.getConstructor(int.class, byte[].class); return ctor.newInstance(0, null); } catch (NoSuchMethodException e) { // ie we are running 1.3 // In 1.3, this constructor has the same behavior, but in 1.4 the default // was changed to add wrapping and newlines. return new Base64(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e.getCause()); } }
From source file:org.omegat.gui.scripting.ScriptRunner.java
private static void invokeGuiScript(Invocable engine) throws ScriptException { Runnable invoke = () -> {/*w ww .ja v a 2 s.co m*/ try { engine.invokeFunction(SCRIPT_GUI_FUNCTION_NAME); } catch (NoSuchMethodException e) { // No GUI invocation defined } catch (ScriptException e) { throw new RuntimeException(e); } }; if (SwingUtilities.isEventDispatchThread()) { invoke.run(); } else { try { SwingUtilities.invokeAndWait(invoke); } catch (InvocationTargetException e) { // The original cause is double-wrapped at this point if (e.getCause().getCause() instanceof ScriptException) { throw (ScriptException) e.getCause().getCause(); } else { Log.log(e); } } catch (InterruptedException e) { Log.log(e); } } }
From source file:org.apache.cassandra.io.compress.CompressionParameters.java
private static ICompressor createCompressor(Class<?> compressorClass, Map<String, String> compressionOptions) throws ConfigurationException { if (compressorClass == null) { if (!compressionOptions.isEmpty()) throw new ConfigurationException("Unknown compression options (" + compressionOptions.keySet() + ") since no compression class found"); return null; }//w w w .j a v a 2s.c o m try { Method method = compressorClass.getMethod("create", Map.class); ICompressor compressor = (ICompressor) method.invoke(null, compressionOptions); // Check for unknown options AbstractSet<String> supportedOpts = Sets.union(compressor.supportedOptions(), GLOBAL_OPTIONS); for (String provided : compressionOptions.keySet()) if (!supportedOpts.contains(provided)) throw new ConfigurationException("Unknown compression options " + provided); return compressor; } catch (NoSuchMethodException e) { throw new ConfigurationException("create method not found", e); } catch (SecurityException e) { throw new ConfigurationException("Access forbiden", e); } catch (IllegalAccessException e) { throw new ConfigurationException("Cannot access method create in " + compressorClass.getName(), e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); throw new ConfigurationException(String.format("%s.create() threw an error: %s", compressorClass.getSimpleName(), cause == null ? e.getClass().getName() + " " + e.getMessage() : cause.getClass().getName() + " " + cause.getMessage()), e); } catch (ExceptionInInitializerError e) { throw new ConfigurationException("Cannot initialize class " + compressorClass.getName()); } }
From source file:com.examples.with.different.packagename.ClassPublicInterface.java
public static <L> void addEventListener(final Object eventSource, final Class<L> listenerType, final L listener) { try {/* w w w . j a v a 2 s. c om*/ MethodUtils.invokeMethod(eventSource, "add" + listenerType.getSimpleName(), listener); } catch (final NoSuchMethodException e) { throw new IllegalArgumentException("Class " + eventSource.getClass().getName() + " does not have a public add" + listenerType.getSimpleName() + " method which takes a parameter of type " + listenerType.getName() + "."); } catch (final IllegalAccessException e) { throw new IllegalArgumentException("Class " + eventSource.getClass().getName() + " does not have an accessible add" + listenerType.getSimpleName() + " method which takes a parameter of type " + listenerType.getName() + "."); } catch (final InvocationTargetException e) { throw new RuntimeException("Unable to add listener.", e.getCause()); } }
From source file:org.apache.cassandra.schema.CompressionParams.java
private static ICompressor createCompressor(Class<?> compressorClass, Map<String, String> compressionOptions) throws ConfigurationException { if (compressorClass == null) { if (!compressionOptions.isEmpty()) throw new ConfigurationException("Unknown compression options (" + compressionOptions.keySet() + ") since no compression class found"); return null; }/* w w w . j a v a 2s.c o m*/ if (compressionOptions.containsKey(CRC_CHECK_CHANCE)) { if (!hasLoggedCrcCheckChanceWarning) { logger.warn(CRC_CHECK_CHANCE_WARNING); hasLoggedCrcCheckChanceWarning = true; } compressionOptions.remove(CRC_CHECK_CHANCE); } try { Method method = compressorClass.getMethod("create", Map.class); ICompressor compressor = (ICompressor) method.invoke(null, compressionOptions); // Check for unknown options for (String provided : compressionOptions.keySet()) if (!compressor.supportedOptions().contains(provided)) throw new ConfigurationException("Unknown compression options " + provided); return compressor; } catch (NoSuchMethodException e) { throw new ConfigurationException("create method not found", e); } catch (SecurityException e) { throw new ConfigurationException("Access forbiden", e); } catch (IllegalAccessException e) { throw new ConfigurationException("Cannot access method create in " + compressorClass.getName(), e); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof ConfigurationException) throw (ConfigurationException) e.getTargetException(); Throwable cause = e.getCause() == null ? e : e.getCause(); throw new ConfigurationException(format("%s.create() threw an error: %s %s", compressorClass.getSimpleName(), cause.getClass().getName(), cause.getMessage()), e); } catch (ExceptionInInitializerError e) { throw new ConfigurationException("Cannot initialize class " + compressorClass.getName()); } }
From source file:org.apache.cassandra.utils.FBUtilities.java
/** * Constructs an instance of the given class, which must have a no-arg constructor. * @param classname Fully qualified classname. * @param readable Descriptive noun for the role the class plays. * @throws ConfigurationException If the class cannot be found. *///w ww .ja va2s .c o m public static <T> T construct(String classname, String readable) throws ConfigurationException { Class<T> cls = FBUtilities.classForName(classname, readable); try { return cls.getConstructor().newInstance(); } catch (NoSuchMethodException e) { throw new ConfigurationException( String.format("No default constructor for %s class '%s'.", readable, classname)); } catch (IllegalAccessException e) { throw new ConfigurationException( String.format("Default constructor for %s class '%s' is inaccessible.", readable, classname)); } catch (InstantiationException e) { throw new ConfigurationException( String.format("Cannot use abstract class '%s' as %s.", classname, readable)); } catch (InvocationTargetException e) { if (e.getCause() instanceof ConfigurationException) throw (ConfigurationException) e.getCause(); throw new ConfigurationException( String.format("Error instantiating %s class '%s'.", readable, classname), e); } }
From source file:com.anrisoftware.globalpom.threads.properties.ThreadingProperties.java
private ThreadFactory createFactory(Class<? extends ThreadFactory> type) throws ThreadsException { try {//from w w w. ja va 2 s . c om return ConstructorUtils.invokeConstructor(type); } catch (NoSuchMethodException e) { throw log.noDefaultCtor(e, type); } catch (IllegalAccessException e) { throw log.illegalAccessCtor(e, type); } catch (InvocationTargetException e) { throw log.exceptionCtor(e.getCause(), type); } catch (InstantiationException e) { throw log.instantiationErrorFactory(e, type); } }
From source file:com.netflix.spinnaker.halyard.config.validate.v1.ValidatorCollection.java
/** * Walk up the object hierarchy, running this validator whenever possible. The idea is, perhaps we were passed a * Kubernetes account, and want to run both the standard Kubernetes account validator to see if the kubeconfig is valid, * as well as the super-classes Account validator to see if the account name is valid. * * @param psBuilder contains the list of problems encountered. * @param validator is the validator to be run. * @param node is the subject of validation. * @param c is some super(inclusive) class of node. * * @return # of validators run (for logging purposes). *///from w w w. j ava 2 s . c o m private int runMatchingValidators(ConfigProblemSetBuilder psBuilder, Validator validator, Node node, Class c) { int result = 0; if (c == Node.class) { return result; } try { Method m = validator.getClass().getMethod("validate", ConfigProblemSetBuilder.class, c); DaemonTaskHandler .log("Validating " + node.getNodeName() + " with " + validator.getClass().getSimpleName()); m.invoke(validator, psBuilder, node); result = 1; } catch (NoSuchMethodException e) { // Do nothing, odds are most validators don't validate every class. } catch (InvocationTargetException | IllegalAccessException e) { log.warn("Failed to invoke validate() on \"" + validator.getClass().getSimpleName() + "\" for node \"" + c.getSimpleName() + "\" with cause " + e.getCause(), e.getCause()); } return runMatchingValidators(psBuilder, validator, node, c.getSuperclass()) + result; }
From source file:com.github.pith.typedconfig.TypedConfigPlugin.java
private Map<Class<Object>, Object> initConfigClasses(Collection<Class<?>> configClasses, Configuration configuration) { Map<Class<Object>, Object> configClassesMap = new HashMap<Class<Object>, Object>(); for (Class<?> configClass : configClasses) { try {//w w w .j a v a2 s. c o m Object configObject = configClass.newInstance(); for (Method method : configClass.getDeclaredMethods()) { if (method.getName().startsWith("get")) { Object property = configuration.getProperty(configClass.getSimpleName().toLowerCase() + method.getName().substring(3).toLowerCase()); if (property != null) { try { Method setter = configClass.getDeclaredMethod("set" + method.getName().substring(3), method.getReturnType()); setter.setAccessible(true); setter.invoke(configObject, property); } catch (NoSuchMethodException e) { throw new IllegalStateException("The TypedConfigPlugin can't initialize " + method.getName() + " because there is no associated setter."); } catch (InvocationTargetException e) { if (e.getCause() != null) { throw new IllegalStateException("Failed to initialize " + method.getName(), e.getCause()); } } } } } //noinspection unchecked configClassesMap.put((Class<Object>) configClass, configObject); } catch (InstantiationException e) { throw new IllegalStateException("Failed to instantiate " + configClass, e.getCause()); } catch (IllegalAccessException e) { throw new IllegalStateException("Failed to access the constructor of " + configClass, e.getCause()); } } return configClassesMap; }
From source file:org.etudes.jforum.Command.java
/** * Process and manipulate a requisition. * @param context TODO/*from w w w . j a v a 2 s . co m*/ * @throws Exception * @return <code>Template</code> reference */ public Template process(ActionServletRequest request, HttpServletResponse response, SimpleHash context) throws Exception { this.request = request; this.response = response; this.context = context; String action = this.request.getAction(); if (logger.isDebugEnabled()) logger.debug("Action = " + action); if (!this.ignoreAction) { try { Object obj[] = null; Class clazz[] = null; if (logger.isDebugEnabled()) logger.debug("Running command on " + this.getClass().getName() + " with method " + action); // Class.forName(this.getClass().getName()).getMethod(action, null).invoke(this, null); Class.forName(this.getClass().getName()).getMethod(action, clazz).invoke(this, obj); } catch (NoSuchMethodException e) { this.list(); } catch (InvocationTargetException e) { if (logger.isErrorEnabled()) { logger.error("Error while performing action: '" + action + "' in the class: " + this.getClass().getName()); logger.error(e.getCause(), e); } throw e; } catch (Exception e) { logger.error("Error while performing action: '" + action + "' in the class: " + this.getClass().getName()); throw e; } } if (JForum.getRedirect() != null) { this.setTemplateName(TemplateKeys.EMPTY); } else if (request.getAttribute("template") != null) { this.setTemplateName((String) request.getAttribute("template")); } if (JForum.isBinaryContent()) { return null; } if (this.templateName == null) { throw new TemplateNotFoundException("Template for action " + action + " is not defined"); } return Configuration.getDefaultConfiguration() .getTemplate(SystemGlobals.getValue(ConfigKeys.TEMPLATE_DIR) + "/" + this.templateName); }