def METHOD_NAME(major, mandatory=True, sysprop_reader=system_property):
    """
    Resolves the path to a JDK with the provided major version.
    :param major: The major version to check.
    :param mandatory: Determines if we expect to find a matching JDK.
    :param sysprop_reader: (Optional) only relevant for testing.
    :return: The resolved path to the JDK or ``None`` if ``mandatory`` is ``False`` and no appropriate JDK has been found.
    """
    def do_resolve(env_var, major):
        java_v_home = os.getenv(env_var)
        if java_v_home:
            actual_major = major_version(java_v_home, sysprop_reader)
            if actual_major == major:
                return java_v_home
            elif mandatory:
                raise exceptions.SystemSetupError(f"{env_var} points to JDK {actual_major} but it should point to JDK {major}.")
            else:
                return None
        else:
            return None
    # this has to be consistent with _checked_env_vars()
    specific_env_var = f"JAVA{major}_HOME"
    generic_env_var = "JAVA_HOME"
    java_home = do_resolve(specific_env_var, major)
    if java_home:
        return java_home
    else:
        java_home = do_resolve(generic_env_var, major)
        if java_home:
            return java_home
        elif mandatory:
            raise exceptions.SystemSetupError(f"Neither {specific_env_var} nor {generic_env_var} point to a JDK {major} installation.")
        else:
            return None