Example usage for java.lang NoSuchMethodException getCause

List of usage examples for java.lang NoSuchMethodException getCause

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.apache.hadoop.hbase.util.CommonFSUtils.java

private static void invokeSetStoragePolicy(final FileSystem fs, final Path path, final String storagePolicy) {
    Method m = null;// w w w  . j a  va 2  s.  c o m
    try {
        m = fs.getClass().getDeclaredMethod("setStoragePolicy", new Class<?>[] { Path.class, String.class });
        m.setAccessible(true);
    } catch (NoSuchMethodException e) {
        final String msg = "FileSystem doesn't support setStoragePolicy; HDFS-6584, HDFS-9345 "
                + "not available. This is normal and expected on earlier Hadoop versions.";
        if (!warningMap.containsKey(fs)) {
            warningMap.put(fs, true);
            LOG.warn(msg, e);
        } else if (LOG.isDebugEnabled()) {
            LOG.debug(msg, e);
        }
        m = null;
    } catch (SecurityException e) {
        final String msg = "No access to setStoragePolicy on FileSystem from the SecurityManager; "
                + "HDFS-6584, HDFS-9345 not available. This is unusual and probably warrants an email "
                + "to the user@hbase mailing list. Please be sure to include a link to your configs, and "
                + "logs that include this message and period of time before it. Logs around service "
                + "start up will probably be useful as well.";
        if (!warningMap.containsKey(fs)) {
            warningMap.put(fs, true);
            LOG.warn(msg, e);
        } else if (LOG.isDebugEnabled()) {
            LOG.debug(msg, e);
        }
        m = null; // could happen on setAccessible() or getDeclaredMethod()
    }
    if (m != null) {
        try {
            m.invoke(fs, path, storagePolicy);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Set storagePolicy=" + storagePolicy + " for path=" + path);
            }
        } catch (Exception e) {
            // This swallows FNFE, should we be throwing it? seems more likely to indicate dev
            // misuse than a runtime problem with HDFS.
            if (!warningMap.containsKey(fs)) {
                warningMap.put(fs, true);
                LOG.warn("Unable to set storagePolicy=" + storagePolicy + " for path=" + path + ". "
                        + "DEBUG log level might have more details.", e);
            } else if (LOG.isDebugEnabled()) {
                LOG.debug("Unable to set storagePolicy=" + storagePolicy + " for path=" + path, e);
            }
            // check for lack of HDFS-7228
            if (e instanceof InvocationTargetException) {
                final Throwable exception = e.getCause();
                if (exception instanceof RemoteException && HadoopIllegalArgumentException.class.getName()
                        .equals(((RemoteException) exception).getClassName())) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Given storage policy, '" + storagePolicy + "', was rejected and probably "
                                + "isn't a valid policy for the version of Hadoop you're running. I.e. if you're "
                                + "trying to use SSD related policies then you're likely missing HDFS-7228. For "
                                + "more information see the 'ArchivalStorage' docs for your Hadoop release.");
                    }
                    // Hadoop 2.8+, 3.0-a1+ added FileSystem.setStoragePolicy with a default implementation
                    // that throws UnsupportedOperationException
                } else if (exception instanceof UnsupportedOperationException) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("The underlying FileSystem implementation doesn't support "
                                + "setStoragePolicy. This is probably intentional on their part, since HDFS-9345 "
                                + "appears to be present in your version of Hadoop. For more information check "
                                + "the Hadoop documentation on 'ArchivalStorage', the Hadoop FileSystem "
                                + "specification docs from HADOOP-11981, and/or related documentation from the "
                                + "provider of the underlying FileSystem (its name should appear in the "
                                + "stacktrace that accompanies this message). Note in particular that Hadoop's "
                                + "local filesystem implementation doesn't support storage policies.",
                                exception);
                    }
                }
            }
        }
    }
}

From source file:com.impetus.ankush2.framework.monitor.AbstractMonitor.java

public void monitor(Cluster cluster, String action, Map parameterMap) {
    this.dbCluster = cluster;
    this.parameterMap = parameterMap;
    result.clear();/*w  ww.  ja va 2s. c om*/
    try {
        this.clusterConf = dbCluster.getClusterConfig();
        Method method = null;
        try {
            // Create method object using the action name.
            method = this.getClass().getDeclaredMethod(action);
        } catch (NoSuchMethodException e) {
            method = this.getClass().getMethod(action);
        } catch (Exception e) {
            throw e;
        }
        // setting accessibility true.
        method.setAccessible(true);
        // invoking the method.
        method.invoke(this);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        if (e.getMessage() != null) {
            addAndLogError(e.getMessage());
        } else {
            addAndLogError(e.getCause().getMessage());
        }
        // Adding and logging error
        addAndLogError("Unable to process request");
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.java

/**
 * Sets an attribute./*from   ww  w. java2s. co m*/
 * See also <a href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-F68F082">
 * the DOM reference</a>
 *
 * @param name Name of the attribute to set
 * @param value Value to set the attribute to
 */
@Override
public void setAttribute(String name, final String value) {
    getDomNodeOrDie().setAttribute(name, value);

    // call corresponding event handler setOnxxx if found
    if (!name.isEmpty()) {
        name = name.toLowerCase(Locale.ROOT);
        if (name.startsWith("on")) {
            try {
                name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
                final Method method = getClass().getMethod("set" + name, METHOD_PARAMS_OBJECT);
                method.invoke(this,
                        new Object[] { new EventHandler(getDomNodeOrDie(), name.substring(2), value) });
            } catch (final NoSuchMethodException e) {
                //silently ignore
            } catch (final IllegalAccessException e) {
                //silently ignore
            } catch (final InvocationTargetException e) {
                throw new RuntimeException(e.getCause());
            }
        }
    }
}

From source file:org.modeldriven.fuml.assembly.ElementAssembler.java

public void associateElement(ElementAssembler other) {
    try {//www  .j  a va2 s  .com
        Property property = other.getPrototype().findProperty(this.getSource().getLocalName());
        if (property == null)
            return; // we validate this elsewhere

        if (!property.isSingular()) {
            if (log.isDebugEnabled())
                log.debug("linking collection property: " + other.getPrototype().getName() + "."
                        + this.getSource().getLocalName() + " with: " + this.getPrototype().getName());
            try {
                String methodName = "add" + this.getSource().getLocalName().substring(0, 1).toUpperCase()
                        + this.getSource().getLocalName().substring(1);
                Method adder = ReflectionUtils.getMethod(other.getTargetClass(), methodName,
                        this.getTargetClass());
                Object[] args = { this.getTargetObject() };
                adder.invoke(other.getTarget(), args);
            } catch (NoSuchMethodException e) {
                // try to get and add to the list field if exists
                try {
                    Field field = other.getTargetClass().getField(this.getSource().getLocalName());
                    Object list = field.get(other.getTargetObject());
                    Method adder = ReflectionUtils.getMethod(list.getClass(), "add", this.getTargetClass());
                    Object[] args = { this.getTargetObject() };
                    adder.invoke(list, args);
                } catch (NoSuchFieldException e2) {
                    log.warn("no 'add' or 'List.add' method found for property, "
                            + other.getPrototype().getName() + "." + this.getSource().getLocalName());
                }
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("linking singular property: " + other.getPrototype().getName() + "."
                        + this.getSource().getLocalName() + " with: " + this.getPrototype().getName());
            try {
                String methodName = "set" + this.getSource().getLocalName().substring(0, 1).toUpperCase()
                        + this.getSource().getLocalName().substring(1);
                Method setter = ReflectionUtils.getMethod(other.getTargetClass(), methodName,
                        this.getTargetClass());
                Object[] args = { this.getTargetObject() };
                setter.invoke(other.getTarget(), args);
            } catch (NoSuchMethodException e) {
                // try to get and add to the list field if exists
                try {
                    Field field = other.getTargetClass().getField(this.getSource().getLocalName());
                    field.set(other.getTargetObject(), this.getTargetObject());
                } catch (NoSuchFieldException e2) {
                    log.warn("no 'set' method or public field found for property, "
                            + other.getPrototype().getName() + "." + this.getSource().getLocalName());
                }
            }
        }
    } catch (NoSuchMethodException e) {
        log.error(e.getMessage(), e);
        throw new AssemblyException(e);
    } catch (InvocationTargetException e) {
        log.error(e.getCause().getMessage(), e.getCause());
        throw new AssemblyException(e.getCause());
    } catch (IllegalAccessException e) {
        log.error(e.getMessage(), e);
        throw new AssemblyException(e);
    }
}

From source file:org.wso2.carbon.user.core.common.AbstractUserStoreManager.java

/**
 * This method is used by the APIs' in the AbstractUserStoreManager
 * to make compatible with Java Security Manager.
 *//*from www.j  av  a2  s  .c o  m*/
private Object callSecure(final String methodName, final Object[] objects, final Class[] argTypes)
        throws UserStoreException {

    final AbstractUserStoreManager instance = this;

    isSecureCall.set(Boolean.TRUE);
    final Method method;
    try {
        Class clazz = Class.forName("org.wso2.carbon.user.core.common.AbstractUserStoreManager");
        method = clazz.getDeclaredMethod(methodName, argTypes);

    } catch (NoSuchMethodException e) {
        log.error("Error occurred when calling method " + methodName, e);
        throw new UserStoreException(e);
    } catch (ClassNotFoundException e) {
        log.error("Error occurred when calling class " + methodName, e);
        throw new UserStoreException(e);
    }

    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
            @Override
            public Object run() throws Exception {
                return method.invoke(instance, objects);
            }
        });
    } catch (PrivilegedActionException e) {
        if (e.getCause() != null && e.getCause().getCause() != null
                && e.getCause().getCause() instanceof UserStoreException) {
            // Actual UserStoreException get wrapped with two exceptions
            throw new UserStoreException(e.getCause().getCause().getMessage(), e);

        } else {
            String msg = "Error occurred while accessing Java Security Manager Privilege Block";
            log.error(msg);
            throw new UserStoreException(msg, e);
        }
    } finally {
        isSecureCall.set(Boolean.FALSE);
    }
}

From source file:com.clark.func.Functions.java

/**
 * Clone an object./* ww  w.ja  va 2 s .c o  m*/
 * 
 * @param <T>
 *            the type of the object
 * @param o
 *            the object to clone
 * @return the clone if the object implements {@link Cloneable} otherwise
 *         <code>null</code>
 * @throws CloneFailedException
 *             if the object is cloneable and the clone operation fails
 * @since 3.0
 */
public static <T> T objectClone(final T o) {
    if (o instanceof Cloneable) {
        final Object result;
        if (o.getClass().isArray()) {
            final Class<?> componentType = o.getClass().getComponentType();
            if (!componentType.isPrimitive()) {
                result = ((Object[]) o).clone();
            } else {
                int length = Array.getLength(o);
                result = Array.newInstance(componentType, length);
                while (length-- > 0) {
                    Array.set(result, length, Array.get(o, length));
                }
            }
        } else {
            try {
                final Method clone = o.getClass().getMethod("clone");
                result = clone.invoke(o);
            } catch (final NoSuchMethodException e) {
                throw new CloneFailedException(
                        "Cloneable type " + o.getClass().getName() + " has no clone method", e);
            } catch (final IllegalAccessException e) {
                throw new CloneFailedException("Cannot clone Cloneable type " + o.getClass().getName(), e);
            } catch (final InvocationTargetException e) {
                throw new CloneFailedException("Exception cloning Cloneable type " + o.getClass().getName(),
                        e.getCause());
            }
        }
        @SuppressWarnings("unchecked")
        final T checked = (T) result;
        return checked;
    }

    return null;
}