# Buggy code
def find_previous_method(self, base_method, top_method, pre_method_list):
    """
    Find the previous method based on base method before top method.
    This will append the method into pre_method_list.

    :param base_method: the base function which needs to be searched.
    :param top_method: the top-level function which calls the basic function.
    :param pre_method_list: list is used to track each function.
    :return: None
    """
    class_name, method_name = base_method
    method_set = self.apkinfo.upperfunc(class_name, method_name)

    if method_set is not None:
        if top_method in method_set:
            pre_method_list.append(base_method)
        else:
            for item in method_set:
                # prevent some functions from looking for themselves.
                if item == base_method:
                    continue
                self.find_previous_method(item, top_method, pre_method_list)


# Traceback (RecursionError)
Traceback (most recent call last):
File "/Users/nick/Desktop/quark-engine/quark/Objects/xrule.py", line 71, in find_previous_method
item, top_method, pre_method_list)
File "/Users/nick/Desktop/quark-engine/quark/Objects/xrule.py", line 71, in find_previous_method
item, top_method, pre_method_list)
File "/Users/nick/Desktop/quark-engine/quark/Objects/xrule.py", line 71, in find_previous_method
item, top_method, pre_method_list)
[Previous line repeated 989 more times]
File "/Users/nick/Desktop/quark-engine/quark/Objects/xrule.py", line 59, in find_previous_method
method_set = self.apkinfo.upperfunc(class_name, method_name)
File "/Users/nick/Desktop/quark-engine/quark/Objects/apkinfo.py", line 60, in upperfunc
method_set = self.find_method(class_name, method_name)
File "/Users/nick/Desktop/quark-engine/quark/Objects/apkinfo.py", line 44, in find_method
if len(list(result)) > 0:
File "/Users/nick/.local/share/virtualenvs/quark-engine-NJwlz3ey/src/androguard/androguard/core/analysis/analysis.py", line 1776, in find_methods
classname = bytes(mutf8.MUTF8String.from_str(classname))
File "/Users/nick/.local/share/virtualenvs/quark-engine-NJwlz3ey/src/androguard/androguard/core/mutf8.py", line 102, in from_str
c = cls(encode(s))
File "/Users/nick/.local/share/virtualenvs/quark-engine-NJwlz3ey/src/androguard/androguard/core/mutf8.py", line 64, in encode
ord_array = [i for i in map(lambda x: ord(x), s)]
File "/Users/nick/.local/share/virtualenvs/quark-engine-NJwlz3ey/src/androguard/androguard/core/mutf8.py", line 64, in <listcomp>
ord_array = [i for i in map(lambda x: ord(x), s)]
File "/Users/nick/.local/share/virtualenvs/quark-engine-NJwlz3ey/src/androguard/androguard/core/mutf8.py", line 64, in <lambda>
ord_array = [i for i in map(lambda x: ord(x), s)]
RecursionError: maximum recursion depth exceeded while calling a Python object

# Fixed code
def find_previous_method(
    self, base_method, top_method, pre_method_list, visited_methods=None
):
    """
    Find the previous method based on base method before top method.
    This will append the method into pre_method_list.

    :param base_method: the base function which needs to be searched.
    :param top_method: the top-level function which calls the basic function.
    :param pre_method_list: list is used to track each function.
    :param visited_methods: set with tested method.
    :return: None
    """
    if visited_methods is None:
        visited_methods = set()

    class_name, method_name = base_method
    method_set = self.apkinfo.upperfunc(class_name, method_name)
    visited_methods.add(base_method)

    if method_set is not None:
        if top_method in method_set:
            pre_method_list.append(base_method)
        else:
            for item in method_set:
                # prevent to test the tested methods.
                if item in visited_methods:
                    continue
                self.find_previous_method(
                    item, top_method, pre_method_list, visited_methods
                )