if (Modifier.isPublic (method.getModifiers ())) method.setAccessible (true);
   private Method [] cachedPublicMethodLookup(String functionName, Class cls) throws EcmaScriptException {        boolean debug = ESLoader.isDebugJavaAccess();        if (publicMethods != null) {           if (debug) System.out.println("** Method descriptor for class '" +                     cls + "' found in cache");            Method [] methods = (Method []) publicMethods.get(functionName);            if (methods!= null) {                if (debug) System.out.println("** " + methods.length +                        " method(s) named '" + functionName + "' found in cache");                return methods;            }        }         // Not in cache, find if any matching the same name can be found         if (debug) System.out.println("** No method named '" +                      functionName + "' found in class cache, lookup started");        Method [] allMethods = cls.getMethods();        Vector methodVector = new Vector(allMethods.length);        boolean wasFound = false;        for (int i=0; i<allMethods.length; i++) {            Method method = allMethods[i];            if (debug) System.out.println("** Method examined: " + method.toString());            if (!method.getName().equals(functionName)) continue;            // Method has same name, some closer examination is needed:            // If the class itself is not public, there is an access error if            // the method is invoked on it - the identical method in the            // superclass must be searched, to be used in the invocation.            // I am not too sure of what happens if the method is defined in an            // interface...            if (!Modifier.isStatic(cls.getModifiers()) && !Modifier.isPublic(cls.getModifiers())) {               if (debug) System.out.println("** Class " + cls +                            " is not public, examining superclasses and interfaces to find proper method descriptor");            Class[] paramTypes = method.getParameterTypes();            SEARCHPUBLIC:               for (Class theClass=cls;theClass!=null;theClass=theClass.getSuperclass()) {                              // Look in interfaces first                    Class [] interfaces = cls.getInterfaces();                   Method m = getInInterfaces(functionName, interfaces, paramTypes);                   if (m != null) {                       method = m;                       wasFound = true;                       break SEARCHPUBLIC;                   }                                      // Look in the class                   if (Modifier.isPublic(theClass.getModifiers())) {                       if (debug) {                           System.out.println("** Looking in public class: " + theClass);                        }                        try {                           m = theClass.getDeclaredMethod(functionName,paramTypes);                           if (Modifier.isPublic(method.getModifiers())) {                               if (debug) {                                   System.out.println("** Public method found: " + functionName);                               }                               method = m;                               wasFound = true;                               break SEARCHPUBLIC;                           }                        } catch (NoSuchMethodException e) {                            if (debug) {                                 System.out.println("** The method has no public declaration in the public class: "+ functionName);                            }                            // throw new ProgrammingError("The method has no public declaration in a public class: "+ functionName);                        } catch (SecurityException e) {                            throw new ProgrammingError("Access error inspecting method "+ functionName + ": " + e);                        }                    } else {                        if (debug) {                           System.out.println("** Class " + theClass + " is not public - not searching for method");                        }                    }                                   } // for SEARCHPUBLIC                              if (!wasFound) {                    throw new EcmaScriptException("The method '" + functionName + "' has no public declaration in a public class or public interface ");               }                           } // if class not public            //  save it            methodVector.addElement(method);        }        // If we have some, cache them        Method [] methods = null;        int nmbMethods = methodVector.size();        if (nmbMethods>0) {           if (debug) System.out.println("** " + nmbMethods + " methods named: '" + functionName + "' + found, add to class cache");            methods = new Method[nmbMethods];            methodVector.copyInto(methods);            if (publicMethods==null) {                publicMethods = new Hashtable();            }            publicMethods.put(functionName, methods);        } else {            if (debug) System.out.println("** No method named '" + functionName + "' found");        }        return methods;    }