Skip to main content

NoSuchMethodException

java.lang.NoSuchMethodException

NoSuchMethodException is described in the javadoc comments as:

Thrown when a particular method cannot be found.
author: unascribed version: 1.13, 12/19/03 since: JDK1.0

Where is this exception thrown?

Following, is a list of exception messages cross-referenced to the source code responsible for throwing them. Click on the method link to view the code and see how the exception is thrown.

How is this exception thrown?

The following sub-sections identify where this exception is thrown, and how (or why) the code is throwing the exception.

Any source code quoted in this section is subject to the Java Research License unless stated otherwise.

java.beans.Statement.invoke()

Object invoke() throws Exception {
    Object target = getTarget();
    String methodName = getMethodName();
    if (target == null || methodName == null) {
        throw new NullPointerException((target == null ? 'target' : 'methodName') + ' should not be null');
    }
    Object[] arguments = getArguments();
    if (target == Class.class && methodName.equals('forName')) {
        return ObjectHandler.classForName((String) arguments[0]);
    }
    Class[] argClasses = new Class[arguments.length];
    for (int i = 0; i < arguments.length; i++) {
        argClasses[i] = (arguments[i] == null) ? null : arguments[i].getClass();
    }
    AccessibleObject m = null;
    if (target instanceof Class) {
        if (methodName.equals('new')) {
            methodName = 'newInstance';
        }
        if (methodName.equals('newInstance') && ((Class) target).isArray()) {
            Object result = Array.newInstance(((Class) target).getComponentType(), arguments.length);
            for (int i = 0; i < arguments.length; i++) {
                Array.set(result, i, arguments[i]);
            }
            return result;
        }
        if (methodName.equals('newInstance') && arguments.length != 0) {
            if (target == Character.class && arguments.length == 1 && argClasses[0] == String.class) {
                return new Character(((String) arguments[0]).charAt(0));
            }
            m = ReflectionUtils.getConstructor((Class) target, argClasses);
        }
        if (m == null && target != Class.class) {
            m = ReflectionUtils.getMethod((Class) target, methodName, argClasses);
        }
        if (m == null) {
            m = ReflectionUtils.getMethod(Class.class, methodName, argClasses);
        }
    } else {
        if (target.getClass().isArray() && (methodName.equals('set') || methodName.equals('get'))) {
            int index = ((Integer) arguments[0]).intValue();
            if (methodName.equals('get')) {
                return Array.get(target, index);
            } else {
                Array.set(target, index, arguments[1]);
                return null;
            }
        }
        m = ReflectionUtils.getMethod(target.getClass(), methodName, argClasses);
    }
    if (m != null) {
        try {
            if (m instanceof Method) {
                return MethodUtil.invoke((Method) m, target, arguments);
            } else {
                return ((Constructor) m).newInstance(arguments);
            }
        } catch (IllegalAccessException iae) {
            throw new Exception('Statement cannot invoke: ' + methodName + ' on ' + target.getClass(), iae);
        } catch (InvocationTargetException ite) {
            Throwable te = ite.getTargetException();
            if (te instanceof Exception) {
                throw (Exception) te;
            } else {
                throw ite;
            }
        }
    }
    throw new NoSuchMethodException(toString());
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

javax.management.relation.RelationService.addRelation(ObjectName)

/**
     * Adds an MBean created by the user (and registered by him in the MBean
     * Server) as a relation in the Relation Service.
     * <P>To be added as a relation, the MBean must conform to the
     * following:
     * <P>- implement the Relation interface
     * <P>- have for RelationService ObjectName the ObjectName of current
     * Relation Service
     * <P>- have a relation id unique and unused in current Relation Service
     * <P>- have for relation type a relation type created in the Relation
     * Service
     * <P>- have roles conforming to the role info provided in the relation
     * type.
     * @param theRelObjectName  ObjectName of the relation MBean to be added.
     * @exception IllegalArgumentException  if null parameter
     * @exception RelationServiceNotRegisteredException  if the Relation
     * Service is not registered in the MBean Server
     * @exception NoSuchMethodException  If the MBean does not implement the
     * Relation interface
     * @exception InvalidRelationIdException  if:
     * <P>- no relation identifier in MBean
     * <P>- the relation identifier is already used in the Relation Service
     * @exception InstanceNotFoundException  if the MBean for given ObjectName
     * has not been registered
     * @exception InvalidRelationServiceException  if:
     * <P>- no Relation Service name in MBean
     * <P>- the Relation Service name in the MBean is not the one of the
     * current Relation Service
     * @exception RelationTypeNotFoundException  if:
     * <P>- no relation type name in MBean
     * <P>- the relation type name in MBean does not correspond to a relation
     * type created in the Relation Service
     * @exception InvalidRoleValueException  if:
     * <P>- the number of referenced MBeans in a role is less than
     * expected minimum degree
     * <P>- the number of referenced MBeans in a role exceeds expected
     * maximum degree
     * <P>- one referenced MBean in the value is not an Object of the MBean
     * class expected for that role
     * <P>- an MBean provided for a role does not exist
     * @exception RoleNotFoundException  if a value is provided for a role
     * that does not exist in the relation type
     */
public void addRelation(ObjectName theRelObjectName) throws IllegalArgumentException, RelationServiceNotRegisteredException, NoSuchMethodException, InvalidRelationIdException, InstanceNotFoundException, InvalidRelationServiceException, RelationTypeNotFoundException, RoleNotFoundException, InvalidRoleValueException {
    if (theRelObjectName == null) {
        String excMsg = 'Invalid parameter.';
        throw new IllegalArgumentException(excMsg);
    }
    if (isTraceOn()) trace('addRelation: entering', theRelObjectName.toString());
    isActive();
    if ((!(myMBeanServer.isInstanceOf(theRelObjectName, 'javax.management.relation.Relation')))) {
        String excMsg = 'This MBean does not implement the Relation interface.';
        throw new NoSuchMethodException(excMsg);
    }
    String relId = null;
    try {
        relId = (String) (myMBeanServer.getAttribute(theRelObjectName, 'RelationId'));
    } catch (MBeanException exc1) {
        throw new RuntimeException((exc1.getTargetException()).getMessage());
    } catch (ReflectionException exc2) {
        throw new RuntimeException(exc2.getMessage());
    } catch (AttributeNotFoundException exc3) {
        throw new RuntimeException(exc3.getMessage());
    }
    if (relId == null) {
        String excMsg = 'This MBean does not provide a relation id.';
        throw new InvalidRelationIdException(excMsg);
    }
    ObjectName relServObjName = null;
    try {
        relServObjName = (ObjectName) (myMBeanServer.getAttribute(theRelObjectName, 'RelationServiceName'));
    } catch (MBeanException exc1) {
        throw new RuntimeException((exc1.getTargetException()).getMessage());
    } catch (ReflectionException exc2) {
        throw new RuntimeException(exc2.getMessage());
    } catch (AttributeNotFoundException exc3) {
        throw new RuntimeException(exc3.getMessage());
    }
    boolean badRelServFlg = false;
    if (relServObjName == null) {
        badRelServFlg = true;
    } else if (!(relServObjName.equals(myObjName))) {
        badRelServFlg = true;
    }
    if (badRelServFlg) {
        String excMsg = 'The Relation Service referenced in the MBean is not the current one.';
        throw new InvalidRelationServiceException(excMsg);
    }
    String relTypeName = null;
    try {
        relTypeName = (String) (myMBeanServer.getAttribute(theRelObjectName, 'RelationTypeName'));
    } catch (MBeanException exc1) {
        throw new RuntimeException((exc1.getTargetException()).getMessage());
    } catch (ReflectionException exc2) {
        throw new RuntimeException(exc2.getMessage());
    } catch (AttributeNotFoundException exc3) {
        throw new RuntimeException(exc3.getMessage());
    }
    if (relTypeName == null) {
        String excMsg = 'No relation type provided.';
        throw new RelationTypeNotFoundException(excMsg);
    }
    RoleList roleList = null;
    try {
        roleList = (RoleList) (myMBeanServer.invoke(theRelObjectName, 'retrieveAllRoles', null, null));
    } catch (MBeanException exc1) {
        throw new RuntimeException((exc1.getTargetException()).getMessage());
    } catch (ReflectionException exc2) {
        throw new RuntimeException(exc2.getMessage());
    }
    addRelationInt(false, null, theRelObjectName, relId, relTypeName, roleList);
    synchronized (myRelMBeanObjName2RelIdMap) {
        myRelMBeanObjName2RelIdMap.put(theRelObjectName, relId);
    }
    try {
        myMBeanServer.setAttribute(theRelObjectName, new Attribute('RelationServiceManagementFlag', new Boolean(true)));
    } catch (Exception exc) {
    }
    ArrayList newRefList = new ArrayList();
    newRefList.add(theRelObjectName);
    updateUnregistrationListener(newRefList, null);
    if (isTraceOn()) trace('addRelation: exiting', null);
    return;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.beans.ReflectionUtils.getPublicMethod(Class, String, Class[])

/**
     * @return the method which best matches the signature or throw an exception
     *         if it can't be found or the method is ambiguous.
     */
static Method getPublicMethod(Class declaringClass, String methodName, Class[] argClasses) throws NoSuchMethodException {
    Method m;
    m = findPublicMethod(declaringClass, methodName, argClasses);
    if (m == null) throw new NoSuchMethodException(declaringClass.getName() + '.' + methodName);
    return m;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.lang.Class.getDeclaredMethod(String, Class)

/**
     * Returns a <code>Method</code> object that reflects the specified
     * declared method of the class or interface represented by this
     * <code>Class</code> object. The <code>name</code> parameter is a
     * <code>String</code> that specifies the simple name of the desired
     * method, and the <code>parameterTypes</code> parameter is an array of
     * <code>Class</code> objects that identify the method's formal parameter
     * types, in declared order.  If more than one method with the same
     * parameter types is declared in a class, and one of these methods has a
     * return type that is more specific than any of the others, that method is
     * returned; otherwise one of the methods is chosen arbitrarily.  If the
     * name is '<init>'or '<clinit>' a <code>NoSuchMethodException</code>
     * is raised.
     * @param name the name of the method
     * @param parameterTypes the parameter array
     * @return    the <code>Method</code> object for the method of this class
     * matching the specified name and parameters
     * @exception NoSuchMethodException if a matching method is not found.
     * @exception NullPointerException if <code>name</code> is <code>null</code>
     * @exception  SecurityException
     *             If a security manager, <i>s</i>, is present and any of the
     *             following conditions is met:
     *             <ul>
     *             <li> invocation of 
     *             <tt>{@link SecurityManager#checkMemberAccess
     *             s.checkMemberAccess(this, Member.DECLARED)}</tt> denies
     *             access to the declared method
     *             <li> the caller's class loader is not the same as or an
     *             ancestor of the class loader for the current class and
     *             invocation of <tt>{@link SecurityManager#checkPackageAccess
     *             s.checkPackageAccess()}</tt> denies access to the package
     *             of this class
     *             </ul>
     * @since JDK1.1
     */
public Method getDeclaredMethod(String name, Class... parameterTypes) throws NoSuchMethodException, SecurityException {
    checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
    Method method = searchMethods(privateGetDeclaredMethods(false), name, parameterTypes);
    if (method == null) {
        throw new NoSuchMethodException(getName() + '.' + name + argumentTypesToString(parameterTypes));
    }
    return method;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.lang.Class.getMethod(String, Class)

/**
     * Returns a <code>Method</code> object that reflects the specified public
     * member method of the class or interface represented by this
     * <code>Class</code> object. The <code>name</code> parameter is a
     * <code>String</code> specifying the simple name the desired method. The
     * <code>parameterTypes</code> parameter is an array of <code>Class</code>
     * objects that identify the method's formal parameter types, in declared
     * order. If <code>parameterTypes</code> is <code>null</code>, it is 
     * treated as if it were an empty array.
     *  If the <code>name</code> is '<init>'or '<clinit>' a
     * <code>NoSuchMethodException</code> is raised. Otherwise, the method to
     * be reflected is determined by the algorithm that follows.  Let C be the
     * class represented by this object:
     * <OL>
     * <LI> C is searched for any <I>matching methods</I>. If no matching
     *      method is found, the algorithm of step 1 is invoked recursively on
     *      the superclass of C.</LI>
     * <LI> If no method was found in step 1 above, the superinterfaces of C
     *      are searched for a matching method. If any such method is found, it
     *      is reflected.</LI>
     * </OL>
     * To find a matching method in a class C:  If C declares exactly one
     * public method with the specified name and exactly the same formal
     * parameter types, that is the method reflected. If more than one such
     * method is found in C, and one of these methods has a return type that is
     * more specific than any of the others, that method is reflected;
     * otherwise one of the methods is chosen arbitrarily.
     *  See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
     * @param name the name of the method
     * @param parameterTypes the list of parameters
     * @return the <code>Method</code> object that matches the specified
     * <code>name</code> and <code>parameterTypes</code>
     * @exception NoSuchMethodException if a matching method is not found
     *            or if the name is '<init>'or '<clinit>'.
     * @exception NullPointerException if <code>name</code> is <code>null</code>
     * @exception  SecurityException
     *             If a security manager, <i>s</i>, is present and any of the
     *             following conditions is met:
     *             <ul>
     *             <li> invocation of 
     *             <tt>{@link SecurityManager#checkMemberAccess
     *             s.checkMemberAccess(this, Member.PUBLIC)}</tt> denies
     *             access to the method
     *             <li> the caller's class loader is not the same as or an
     *             ancestor of the class loader for the current class and
     *             invocation of <tt>{@link SecurityManager#checkPackageAccess
     *             s.checkPackageAccess()}</tt> denies access to the package
     *             of this class
     *             </ul>
     * @since JDK1.1
     */
public Method getMethod(String name, Class... parameterTypes) throws NoSuchMethodException, SecurityException {
    checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
    Method method = getMethod0(name, parameterTypes);
    if (method == null) {
        throw new NoSuchMethodException(getName() + '.' + name + argumentTypesToString(parameterTypes));
    }
    return method;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.lang.Class.getConstructor0(Class[], int)

private Constructor<T> getConstructor0(Class[] parameterTypes, int which) throws NoSuchMethodException {
    Constructor[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC));
    for (int i = 0; i < constructors.length; i++) {
        if (arrayContentsEq(parameterTypes, constructors[i].getParameterTypes())) {
            return getReflectionFactory().copyConstructor(constructors[i]);
        }
    }
    throw new NoSuchMethodException(getName() + '.<init>' + argumentTypesToString(parameterTypes));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Comments

Popular posts from this blog

BAD_CERTIFICATE - A corrupt or unuseable certificate...

This is a simple symptom-cause-solution blog entry only. I hope these blogs will help fellow administrators.
Symptom
In wls_utc, when trying to test a webservice using SSL, the following error message is received: javax.net.ssl.SSLKeyException: FATAL Alert:BAD_CERTIFICATE - A corrupt or unuseable certificate was received.
If SSL debugging is enabled, the following error also appears in the logs: ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)' <1254822672320>>
verification failed because RSA key public exponent [3] is too small
Cause
The certificate encryption is of a weaker strength than expected by newer versions of Java.
Solution
Add the flag "-Dweblogic.security.SSL.allowSmallRSAExponent=true" to the server startup parameters.
References


None.

Connection refused: No available router to destination

This is a simple symptom-cause-solution blog entry only. I hope these blogs will help fellow administrators.
Symptom

The following exception occurs in WebLogic server logs. Most likely to occur during WebLogic server start-up, but similar exceptions may occur at other times.
java.net.ConnectException: t3://myserver:8000: Destination unreachable; nested exception is: java.net.ConnectException: Connection refused: connect; No available router to destination] at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:49) at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:773) at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:363) at weblogic.jndi.Environment.getContext(Environment.java:307) at weblogic.jndi.Environment.getContext(Environment.java:277)
Cause
This message (Connection refused: connect; No available router to destination) is a kind of "catch…

WebLogic Admin Console

WebLogic Admin Console
The WebLogic Admin Console is a web-based, user interface used to configure and control a set of WebLogic servers or clusters (i.e. a "domain"). In any logical group of WebLogic servers there must exist one admin server, which hosts the WebLogic Admin Console application and manages the associated configuration files.
WebLogic Administrators will use the Administration Console for a number of tasks, including:
Starting and stopping WebLogic servers or entire clusters.Configuring server parameters, security, database connections and deployed applications.Viewing server status, health and metrics. Note: It is not strictly necessary to use the Weblogic Admin Console to perform these tasks, as they can be scripted using WLST (the WebLogic Scripting Tool).
Accessing the Admin Console
WebLogic Admin Console Url: http://hostname:port/console.
To access the WebLogic Administration Console, assuming the admin server has been started, goto the above url. Where hostname…