Example usage for java.lang NoSuchMethodException getMessage

List of usage examples for java.lang NoSuchMethodException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.jradius.server.Main.java

public static void main(String[] args) {
    if (args.length != 1) {
        showUsage();//from  w w w .j a  v  a2s .  c  o m
        System.exit(1);
    }

    /**
     * CADBiS daemon run
     * --->
     */
    if (JRadiusConfigurator.getInstance().getProperty("cadbis_daemon").equals("enabled"))
        CADBiS.getInstance().start();
    /**
     * <--- eof CADBiS
     */

    String configFilePath = args[0];

    try {
        File file = new File(configFilePath);
        Configuration.initialize(file);
        JRadiusServer server = new JRadiusServer();
        server.start();
    } catch (FileNotFoundException e) {
        System.err.println("Error: The configuration file '" + configFilePath + "' does not exist.");
    } catch (ConfigurationException e1) {
        System.err.println("Error: The configuration file could not be read,"
                + " because the file contains an error: " + e1.getMessage());
        showStackTrace(e1);
    } catch (SecurityException e2) {
        System.err.println("Error: The configuration file could not be read,"
                + " because a security error occurred: " + e2.getMessage());
        showStackTrace(e2);
    } catch (IllegalArgumentException e3) {
        System.err.println("Error: The configuration file could not be read,"
                + " because an illegal argument error occurred: " + e3.getMessage());
        showStackTrace(e3);
    } catch (ClassNotFoundException e4) {
        System.err.println("Error: The configuration file could not be read,"
                + " because a class specified in the configuration file could not be found: "
                + e4.getMessage());
        showStackTrace(e4);
    } catch (NoSuchMethodException e5) {
        System.err.println("Error: The configuration file could not be read,"
                + " because a method does not exist in a class specified in the configuration file: "
                + e5.getMessage());
        showStackTrace(e5);
    } catch (InstantiationException e6) {
        System.err.println("Error: The configuration file could not be read,"
                + " because an object specified in the configuration file could not be instantiated: "
                + e6.getMessage());
        showStackTrace(e6);
    } catch (IllegalAccessException e7) {
        System.err.println("Error: The configuration file could not be read,"
                + " because an illegal access error occurred: " + e7.getMessage());
        showStackTrace(e7);
    } catch (InvocationTargetException e8) {
        System.err.println("Error: The configuration file could not be read,"
                + " because an invocation target exception was thrown: " + e8.getMessage());
        showStackTrace(e8);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return;
}

From source file:Main.java

static Method getMethod(Class<?> clz, final String mtdName, Class<?>[] mtdArgs) {
    if (clz == null || TextUtils.isEmpty(mtdName) || mtdArgs == null) {
        return null;
    }/*from  www  . j a va2s .com*/
    Method mtd = null;
    try {
        mtd = clz.getDeclaredMethod(mtdName, mtdArgs);
        mtd.setAccessible(true);
    } catch (NoSuchMethodException e) {
        Log.d(TAG, e.getMessage(), e);
    }
    return mtd;
}

From source file:Main.java

public static Object clone(final Object obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }/*from w w w.jav  a  2  s .  co  m*/
    if (obj instanceof Cloneable) {
        Class<?> clazz = obj.getClass();
        Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            return m.invoke(obj, (Object[]) null);
        } catch (InvocationTargetException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:Main.java

/**
 * @since 4.3/* ww w. ja v a  2  s .c  o  m*/
 */
public static <T> T cloneObject(final T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {
        final Class<?> clazz = obj.getClass();
        final Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (final NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            @SuppressWarnings("unchecked")
            // OK because clone() preserves the class
            final T result = (T) m.invoke(obj, (Object[]) null);
            return result;
        } catch (final InvocationTargetException ex) {
            final Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (final IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:Main.java

/**
 * @since 4.3/*from  w  ww.ja  va  2 s. c  o  m*/
 */
public static <T> T cloneObject(final T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {
        final Class<?> clazz = obj.getClass();
        final Method m;
        try {
            m = clazz.getMethod("clone", (Class<?>[]) null);
        } catch (final NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            @SuppressWarnings("unchecked")
            // OK because clone() preserves the class
            final T result = (T) m.invoke(obj, (Object[]) null);
            return result;
        } catch (final InvocationTargetException ex) {
            final Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (final IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:no.sesat.search.datamodel.generic.MapDataObjectBeanInfo.java

/** Work around for 4984912.
 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4984912
 * TODO remove with java6//w  w  w  .  ja  v  a2 s. com
 **/
private static void fixForJavaBug4984912(final Class<?> cls, final MappedPropertyDescriptor mpd)
        throws IntrospectionException {

    try {
        final String name = mpd.getName();
        final String captialised = Character.toUpperCase(name.charAt(0)) + name.substring(1);
        Method m = null;
        try {
            // try plural with "s" first, then fall back onto "es"
            m = cls.getMethod("get" + captialised + 's', new Class[0]);
        } catch (NoSuchMethodException nsme) {
            // who on earth designed the english language!?? :@
            m = cls.getMethod("get" + captialised + "es", new Class[0]);
        }
        mpd.setReadMethod(m);

    } catch (NoSuchMethodException ex) {
        LOG.error(ex.getMessage(), ex);
    } catch (SecurityException ex) {
        LOG.error(ex.getMessage(), ex);
    }
}

From source file:org.apache.ibatis.cache.TransactionalCacheManager.java

/**
 * ?// w  w w.  ja va  2  s.  c  o  m
 * @param ?
 * @return   ??
 * @throws CloneNotSupportedException
 */
@SuppressWarnings("unchecked")
public static <T> T cloneObject(T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {//implement Cloneable?clone
        Class<? extends Object> clazz = obj.getClass();
        Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            Object result = m.invoke(obj, (Object[]) null);
            return (T) result;
        } catch (InvocationTargetException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            }
            throw new Error("Unexpected exception", cause);
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    }
    if (obj instanceof Serializable)//??????
        return (T) SerializationUtils.clone((Serializable) obj);
    throw new SerializationException();
}

From source file:org.mule.util.BeanUtils.java

/**
 * Similar to {@link #describe(Object)} except that it will only populate bean properties where there is a valid
 * getter and setter method. Basically this method will describe a bean and honour its encapsulation.
 *
 * @param object the object to describe/*from  ww  w.j  a v  a 2 s  . c  om*/
 * @return a map of published properties
 */
public static Map<String, Object> describeBean(Object object) {
    Map<String, Object> props = new HashMap<String, Object>();
    for (int i = 0; i < object.getClass().getMethods().length; i++) {
        Method method = object.getClass().getMethods()[i];
        if (method.getName().startsWith("get") || method.getName().startsWith("is")) {
            String field = (method.getName().startsWith("is") ? method.getName().substring(2)
                    : method.getName().substring(3));
            String setter = "set" + field;
            try {
                object.getClass().getMethod(setter, method.getReturnType());
            } catch (NoSuchMethodException e) {
                logger.debug("Ignoring bean property: " + e.getMessage());
                continue;
            }
            field = field.substring(0, 1).toLowerCase() + field.substring(1);
            try {
                props.put(field, method.invoke(object));
            } catch (Exception e) {
                logger.debug("unable to call bean method: " + method);
            }
        }
    }
    return props;
}

From source file:jp.terasoluna.fw.util.ExceptionUtil.java

/**
 * ?????/*  www  .j  ava 2s  . c  om*/
 * 
 * <p>
 *  ??????????????
 *  ????????
 *  ???getRootCause()????????ServletException??
 * </p>
 *
 * @param throwable 
 * @return ???
 */
public static String getStackTrace(Throwable throwable) {
    StringBuilder sb = new StringBuilder();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    while (throwable != null) {
        baos.reset();
        throwable.printStackTrace(new PrintStream(baos));
        sb.append(baos.toString());

        //throwable?Class??
        Class<? extends Throwable> throwableClass = throwable.getClass();

        // ServletException ?? getRootCause ?
        if (SERVLET_EXCEPTION_NAME.equals(throwableClass.getName())) {
            try {
                //throwable = ((ServletException) throwable).getRootCause()
                //Class??????
                Method method = throwableClass.getMethod(GET_ROOT_CAUSE);
                throwable = (Throwable) method.invoke(throwable);
            } catch (NoSuchMethodException e) {
                //???????
                log.error(e.getMessage());
                throwable = null;
            } catch (IllegalAccessException e) {
                //?????????
                log.error(e.getMessage());
                throwable = null;
            } catch (InvocationTargetException e) {
                //?????
                log.error(e.getMessage());
                throwable = null;
            }

        } else {
            throwable = throwable.getCause();
        }
    }
    return sb.toString();
}

From source file:com.opengamma.util.ReflectionUtils.java

/**
 * Finds a constructor from a Class.//www  . ja v  a 2  s  . com
 * 
 * @param <T> the type
 * @param type  the type to create, not null
 * @param paramTypes  the parameter types, not null
 * @return the constructor, not null
 * @throws RuntimeException if the class cannot be loaded
 */
public static <T> Constructor<T> findConstructor(final Class<T> type, final Class<?>... paramTypes) {
    try {
        return type.getConstructor(paramTypes);
    } catch (NoSuchMethodException ex) {
        throw new OpenGammaRuntimeException(ex.getMessage(), ex);
    }
}