/*
Call a get method. Any object returned from the call is passed to the
configure method to consume the remaining elements. @param obj @param
node

@return @exception Exception
557787
private Object get(Object obj, Element node) throws Exception {
		Class<?> oClass = nodeClass(node);
		//CHECKSTYLE:OFF
		if (oClass != null) {
			obj = null;
		} else {
			oClass = obj.getClass();
		}
		//CHECKSTYLE:ON

		String name = getAttribute(node, "name");
		String id = getAttribute(node, "id");
		if (LOG.isDebugEnabled()) {
			LOG.debug("XML get " + name);
		}

		//CHECKSTYLE:OFF
		try {
			// try calling a getXxx method.
			Method method = oClass.getMethod("get"
							+ name.substring(0, 1).toUpperCase() + name.substring(1),
					(java.lang.Class[]) null);
			obj = method.invoke(obj, ((java.lang.Object[]) null));
			configure(obj, node, 0);
		} catch (NoSuchMethodException nsme) {
			try {
				Field field = oClass.getField(name);
				obj = field.get(obj);
				configure(obj, node, 0);
			} catch (NoSuchFieldException nsfe) {
				throw nsme;
			}
		}
		//CHECKSTYLE:ON
		if (id != null) {
			_idMap.put(id, obj);
		}
		return obj;
	}
583597
private void visitInvoke(InvokeInstruction obj) {
        assert obj != null;
        try {
            TaintMethodConfig methodConfig = getMethodConfig(obj);
            ObjectType realInstanceClass = (methodConfig == null) ?
                    null : methodConfig.getOutputTaint().getRealInstanceClass();
            Taint taint = getMethodTaint(methodConfig);
            assert taint != null;
            if (FindSecBugsGlobalConfig.getInstance().isDebugTaintState()) {
                taint.setDebugInfo(obj.getMethodName(cpg) + "()"); //TODO: Deprecated debug info
            }
            taint.addSource(new UnknownSource(UnknownSourceType.RETURN,taint.getState()).setSignatureMethod(obj.getClassName(cpg).replace(".","/")+"."+obj.getMethodName(cpg)+obj.getSignature(cpg)));
            if (taint.isUnknown()) {
                taint.addLocation(getTaintLocation(), false);
            }
            taintMutableArguments(methodConfig, obj);
            transferTaintToMutables(methodConfig, taint); // adds variable index to taint too
            Taint taintCopy = new Taint(taint);
            // return type is not always the instance type
            taintCopy.setRealInstanceClass(realInstanceClass);

            TaintFrame tf = getFrame();

            int stackDepth = tf.getStackDepth();
            int nbParam = getNumWordsConsumed(obj);
            List<Taint> parameters = new ArrayList<>(nbParam);
            for(int i=0;i<Math.min(stackDepth,nbParam);i++) {
                parameters.add(new Taint(tf.getStackValue(i)));
            }

            modelInstruction(obj, getNumWordsConsumed(obj), getNumWordsProduced(obj), taintCopy);

            for(TaintFrameAdditionalVisitor visitor : visitors) {
                try {
                    visitor.visitInvoke(obj, methodGen, getFrame() , parameters, cpg);
                }
                catch (Throwable e) {
                    LOG.log(Level.SEVERE,"Error while executing "+visitor.getClass().getName(),e);
                }
            }

        } catch (Exception e) {
            String className = ClassName.toSlashedClassName(obj.getReferenceType(cpg).toString());
            String methodName = obj.getMethodName(cpg);
            String signature = obj.getSignature(cpg);

            throw new RuntimeException("Unable to call " + className + '.' + methodName + signature, e);
        }
    }
1178141
public static Object getValue(Object obj, String field) {
        Method getter = getGetterMethod(obj.getClass(), field);

        try {
            return getter.invoke(obj);
        } catch (IllegalAccessException | InvocationTargetException e) {
            return null;
        }
    }
825442
public void configure(Object obj, Element cfg, int startIdx)
			throws Exception {
		String id = getAttribute(cfg, "id");
		if (id != null) {
			_idMap.put(id, obj);
		}

		Element[] children = getChildren(cfg);

		for (int i = startIdx; i < children.length; i++) {
			Element node = children[i];
			//CHECKSTYLE:OFF
			try {
				// TODO: in case switching to jdk 7, this could be a switch!
				String tag = node.getTagName();
				if ("Set".equals(tag)) {
					set(obj, node);
				} else if ("Put".equals(tag)) {
					put(obj, node);
				} else if ("Call".equals(tag)) {
					call(obj, node);
				} else if ("Get".equals(tag)) {
					get(obj, node);
				} else if ("New".equals(tag)) {
					newObj(obj, node);
				} else if ("Array".equals(tag)) {
					newArray(obj, node);
				} else if ("Ref".equals(tag)) {
					refObj(obj, node);
				} else if ("Property".equals(tag)) {
					propertyObj(obj, node);
				} else {
					throw new IllegalStateException("Unknown tag: " + tag);
				}
			} catch (Exception e) {
				LOG.warn("Config error at " + node, e.toString());
				throw e;
			}
			//CHECKSTYLE:ON
		}
	}
988990
@SuppressWarnings({"unchecked", "rawtypes"})
    private Object fromXml(Class<?> clazz, Element node) throws Exception {
        Object obj = clazz.newInstance();

        List<Element> subNodes = node.elements();
        int sizeOfSubNodes = subNodes.size();

        for (int i = 0; i < sizeOfSubNodes; i++) {
            Element e = subNodes.get(i);
            String tagName = e.getName();

            Field field = null;
            if (TypeUtil.isPrimitiveType(tagName)) {
                field = clazz.getField("_" + tagName);
            }
            else {
                field = clazz.getField(tagName);
            }

            Class<?> fType = field.getType();
            boolean isFieldArray = fType.isArray();
            //if field is an array, adjust it to the component type
            if (isFieldArray) {
                fType = fType.getComponentType();
            }

            Class fRealType = fType;
            String xsiType = e.attributeValue(SoapConsts.XSI_TYPE);
            if (xsiType != null && (!xsiType.startsWith("xsd:"))) {
                fRealType = TypeUtil.getVimClass(xsiType);
            }

            if (fRealType == ManagedObjectReference.class) { // MOR
                if (isFieldArray) {
                    int sizeOfFieldArray = getNumberOfSameTags(subNodes, sizeOfSubNodes, i, tagName);
                    ManagedObjectReference[] mos = new ManagedObjectReference[sizeOfFieldArray];
                    for (int j = 0; j < sizeOfFieldArray; j++) {
                        Element elem = subNodes.get(j + i);
                        mos[j] = MorUtil.createMOR(elem.attributeValue("type"), elem.getText());
                    }
                    field.set(obj, mos);
                    i = i + sizeOfFieldArray - 1;
                }
                else {
                    field.set(obj, MorUtil.createMOR(e.attributeValue("type"), e.getText()));
                }
            }
            else if (fRealType.isEnum()) { // Enum type
                if (!isFieldArray) {
                    Object fo = Enum.valueOf(fRealType, e.getText());
                    field.set(obj, fo);
                }
                else {
                    int sizeOfFieldArray = getNumberOfSameTags(subNodes, sizeOfSubNodes, i, tagName);
                    Object ao = Array.newInstance(fRealType, sizeOfFieldArray);
                    for (int j = 0; j < sizeOfFieldArray; j++) {
                        String enumStr = ((Element) subNodes.get(j + i)).getText();
                        Array.set(ao, j, Enum.valueOf(fRealType, enumStr));
                    }
                    field.set(obj, ao);
                    i = i + sizeOfFieldArray - 1;
                }
            }
            else if (TypeUtil.isBasicType(fRealType)) { // basic data types
                if (isFieldArray) {
                    int sizeOfFieldArray = getNumberOfSameTags(subNodes, sizeOfSubNodes, i, tagName);

                    List<String> values = new ArrayList<String>();
                    for (int j = 0; j < sizeOfFieldArray; j++) {
                        values.add(subNodes.get(j + i).getText());
                    }

                    String fTrueType;
                    if (xsiType != null) {
                        fTrueType = xsiType.substring("xsd:".length()) + "[]";
                    }
                    else {
                        fTrueType = fRealType.getSimpleName();
                        if (!fTrueType.endsWith("[]")) {
                            fTrueType = fTrueType + "[]";
                        }
                    }
                    ReflectUtil.setObjectArrayField(obj, field, fTrueType, values);
                    i = i + sizeOfFieldArray - 1;
                }
                else {
                    if (xsiType != null) {
                        xsiType = xsiType.substring("xsd:".length());
                        ReflectUtil.setObjectField(obj, field, xsiType, e.getText());
                    }
                    else {
                        ReflectUtil.setObjectField(obj, field, fRealType.getSimpleName(), e.getText());
                    }
                }
            }
            else { //VIM type
                if (isFieldArray) {
                    int sizeOfFieldArray = getNumberOfSameTags(subNodes, sizeOfSubNodes, i, tagName);
                    // arrayTypeName = arrayTypeName.substring(0, arrayTypeName.length()-2);
                    Object ao = Array.newInstance(fType, sizeOfFieldArray);
                    String fGenericType = fType.getSimpleName();
                    for (int j = 0; j < sizeOfFieldArray; j++) {
                        Element elem = subNodes.get(j + i);
                        String elemXsiType = elem.attributeValue(SoapConsts.XSI_TYPE);
                        String elemType = elemXsiType != null ? elemXsiType : fGenericType;
                        Object o = fromXml(TypeUtil.getVimClass(elemType), elem);
                        Array.set(ao, j, o);
                    }
                    field.set(obj, ao);
                    i = i + sizeOfFieldArray - 1;
                }
                else { // single VIM
                    Object o = fromXml(fRealType, e);
                    field.set(obj, o);
                }
            }
        }
        return obj;
    }
704447
@SuppressWarnings("unchecked")
	public Object invoke(Object object) throws Exception {
		if (object == null) throw new NullPointerException("object");

		for (Invocation invocation : toChain()) {
			MethodDescriptor<Object, Object> unchecked =
					(MethodDescriptor<Object, Object>) invocation.method;
			object = unchecked.invoke(object, invocation.getArgsWithDefaults());
		}

		return object;
	}
21377
private Object newObj(Object obj, Element node) throws Exception {
		Class<?> oClass = nodeClass(node);
		String id = getAttribute(node, "id");
		int size = 0;
		Element[] children = getChildren(node);
		int argi = children.length;
		for (int i = 0; i < children.length; i++) {
			Element element = children[i];

			if (!(element.getTagName().equals("Arg"))) {
				argi = i;
				break;
			}
			size++;
		}

		//CHECKSTYLE:OFF
		Object[] arg = new Object[size];
		for (int i = 0, j = 0; j < size; i++) {
			Element o = children[i];
			arg[j++] = value(obj, o);
		}
		//CHECKSTYLE:ON

		if (LOG.isDebugEnabled()) {
			LOG.debug("XML new " + oClass);
		}

		// Lets just try all constructors for now
		Constructor<?>[] constructors = oClass.getConstructors();
		for (int c = 0; constructors != null && c < constructors.length; c++) {
			if (constructors[c].getParameterTypes().length != size) {
				continue;
			}

			Object n = null;
			boolean called = false;
			try {
				n = constructors[c].newInstance(arg);
				called = true;
			} catch (IllegalAccessException e) {
				if (LOG.isInfoEnabled()) {
					LOG.info(
							"IllegalAccessException while parsing jetty-web.xml",
							e);
				}
			} catch (InstantiationException e) {
				if (LOG.isInfoEnabled()) {
					LOG.info(
							"InstantiationException while parsing jetty-web.xml",
							e);
				}
			} catch (IllegalArgumentException e) {
				if (LOG.isInfoEnabled()) {
					LOG.info(
							"IllegalArgumentException while parsing jetty-web.xml",
							e);
				}
			}
			if (called) {
				if (id != null) {
					_idMap.put(id, n);
				}
				configure(n, node, argi);
				return n;
			}
		}

		throw new IllegalStateException("No Constructor: " + node + " on "
				+ obj);
	}
993139
public Object extFunction(String ns, String funcName, Vector argVec,
        Object methodKey) throws javax.xml.transform.TransformerException {
        try {

            if ( funcName == null ) {
                String fmsg = XSLMessages.createXPATHMessage(
                    XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
                    new Object[] {"Function Name"} );
                throw new NullPointerException ( fmsg ); 
            }
            //Find the XPathFunction corresponding to namespace and funcName
            javax.xml.namespace.QName myQName = new QName( ns, funcName );

            // JAXP 1.3 spec says When XMLConstants.FEATURE_SECURE_PROCESSING 
            // feature is set then invocation of extension functions need to
            // throw XPathFunctionException
            if ( extensionInvocationDisabled ) {
                String fmsg = XSLMessages.createXPATHMessage(
                    XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED,
                    new Object[] { myQName.toString() } );
                throw new XPathFunctionException ( fmsg );
            }

            // Assuming user is passing all the needed parameters ( including
            // default values )
            int arity = argVec.size();

            javax.xml.xpath.XPathFunction xpathFunction = 
                resolver.resolveFunction ( myQName, arity );

            // not using methodKey
            ArrayList argList = new ArrayList( arity);
            for ( int i=0; i<arity; i++ ) {
                Object argument = argVec.elementAt( i );
                // XNodeSet object() returns NodeVector and not NodeList
                // Explicitly getting NodeList by using nodelist()
                if ( argument instanceof XNodeSet ) {
                    argList.add ( i, ((XNodeSet)argument).nodelist() );
                } else if ( argument instanceof XObject ) {
                    Object passedArgument = ((XObject)argument).object();
                    argList.add ( i, passedArgument );
                } else {
                    argList.add ( i, argument );
                }
            }

            return ( xpathFunction.evaluate ( argList ));
        } catch ( XPathFunctionException xfe ) {
            // If we get XPathFunctionException then we want to terminate
            // further execution by throwing WrappedRuntimeException 
            throw new org.apache.xml.utils.WrappedRuntimeException ( xfe );
        } catch ( Exception e ) {
            throw new javax.xml.transform.TransformerException ( e );
        }
    
    }
1118914
private Object refObj(Object obj, XmlParser.Node node) throws NoSuchMethodException,
            ClassNotFoundException, InvocationTargetException, IllegalAccessException
    {
        String id = node.getAttribute("id");
        obj = _idMap.get(id);
        if (obj == null) throw new IllegalStateException("No object for id=" + id);
        configure(obj, node, 0);
        return obj;
    }
1046709
public static Object invokeMethod(Object obj, Method method, Object... params) {
        try {
            method.setAccessible(true);
            return method.invoke(obj, params);
        }
        catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException ex) {
            throw new RuntimeException(ex);
        }
    }
1042733
private ObjectNode makeRequest(final String api, final JsiiObjectRef objRef) {
        ObjectNode req = makeRequest(api);
        req.set("objref", objRef.toJson());
        return req;
    }
1213496
public static Object callMethod(Object obj, String methodName, Object[] args) throws PageException {
	return callMethod(obj, KeyImpl.getInstance(methodName), args);
    }
848358
public static Object invokeMethod(Object obj, Method method, Object... parameter) {
        try {
            method.setAccessible(true);
            return method.invoke(obj, parameter);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }
547607
private void configure(Object obj, XmlParser.Node cfg, int i) throws ClassNotFoundException,
            NoSuchMethodException, InvocationTargetException, IllegalAccessException
    {
        XmlParser.Node node = null;
        try
        {
            for (; i < cfg.size(); i++)
            {
                Object o = cfg.get(i);
                if (o instanceof String) continue;
                node = (XmlParser.Node) o;

                String tag = node.getTag();
                if ("Set".equals(tag))
                    set(obj, node);
                else if ("Put".equals(tag))
                    put(obj, node);
                else if ("Call".equals(tag))
                    call(obj, node);
                else if ("Get".equals(tag))
                    get(obj, node);
                else if ("New".equals(tag))
                    newObj(obj, node);
                else if ("Ref".equals(tag))
                    refObj(obj, node);
                else
                    throw new IllegalStateException("Unknown tag: " + tag);
            }
        }
        catch(InvocationTargetException e)
        {
            log.warn("Exception at "+node.toString(),e.getTargetException());
            throw e;
        }
        catch (Error e)
        {
            log.debug(node);
            throw e;
        }
        catch (Exception e)
        {
            log.debug(node);
            if (e instanceof NoSuchMethodException) throw (NoSuchMethodException) e;
            if (e instanceof InvocationTargetException) throw (InvocationTargetException) e;
            if (e instanceof IllegalAccessException) throw (IllegalAccessException) e;
            if (e instanceof RuntimeException) throw (RuntimeException) e;
        }
    }
623069
@Override
    public void visitCode(Code obj) {
        try {

            ignoreRegs.clear();
            Method method = getMethod();
            if (!method.isStatic()) {
                ignoreRegs.set(0);
            }

            int[] parmRegs = RegisterUtils.getParameterRegisters(method);
            for (int parm : parmRegs) {
                ignoreRegs.set(parm);
            }

            rootScopeBlock = new ScopeBlock(0, obj.getLength());
            tryBlocks.clear();
            catchHandlers.clear();
            CodeException[] exceptions = obj.getExceptionTable();
            if (exceptions != null) {
                for (CodeException ex : exceptions) {
                    tryBlocks.set(ex.getStartPC());
                    catchHandlers.set(ex.getHandlerPC());
                }
            }

            switchTargets.clear();
            stack.resetForMethodEntry(this);
            dontReport = false;
            sawDup = false;
            sawNull = false;
            super.visitCode(obj);

            if (!dontReport) {
                rootScopeBlock.findBugs(new HashSet<Integer>());
            }

        } finally {
            rootScopeBlock = null;
        }
    }
4420
private static Object _runMethod(Object obj, String methodName)
    {
        try
        {
            Method sessionIdMethod = obj.getClass().getMethod(methodName);
            return sessionIdMethod.invoke(obj);
        }
        catch (Exception e)
        {
            return null;
        }

    }
894240
public static <T> Object callMethod(Object obj,
                                        Class<T> c,
                                        String name,
                                        Class<?>[] classes,
                                        Object[] args) {
        try {
            Method m = getMethod(c, name, classes);
            return m.invoke(obj, args);
        } catch(InvocationTargetException e) {
            throw getCause(e);
        } catch(IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
    }