Skip to content

<uiautomator2.Device>.dump_hierarchy() causes java.lang.NullPointerException in certain screens (java.lang.NullPointerException) #1138

@felipegetulio

Description

@felipegetulio

Hi, is there already an issue for this?

device.dump_hierarchy(compressed=compressed, pretty=pretty, max_depth=max_depth)
my-venv/lib/python3.10/site-packages/uiautomator2/__init__.py:107: in dump_hierarchy
    content = self._do_dump_hierarchy(compressed, max_depth)
my-venv/lib/python3.10/site-packages/decorator.py:235: in fun
    return caller(func, *(extras + args), **kw)
my-venv/lib/python3.10/site-packages/retry/api.py:90: in retry_decorator
    return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
my-venv/lib/python3.10/site-packages/retry/api.py:35: in __retry_internal
    return f()
my-venv/lib/python3.10/site-packages/uiautomator2/__init__.py:122: in _do_dump_hierarchy
    content = self.jsonrpc.dumpWindowHierarchy(compressed, max_depth)
my-venv/lib/python3.10/site-packages/uiautomator2/base.py:158: in __call__
    return self.server.jsonrpc_call(self.method, params, http_timeout)
my-venv/lib/python3.10/site-packages/uiautomator2/core.py:311: in jsonrpc_call
    return _jsonrpc_call(self._dev, self._device_server_port, method, params, timeout, self._debug)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

dev = AdbDevice(serial=NW6T110101), device_port = 9008
method = 'dumpWindowHierarchy', params = (False, 50), timeout = 300
print_request = False

    def _jsonrpc_call(dev: adbutils.AdbDevice, device_port: int, method: str, params: Any, timeout: float, print_request: bool) -> Any:
        """Send jsonrpc call to uiautomator2 server
    
        Raises:
            UiAutomationError
        """
        payload = {
            "jsonrpc": "2.0",
            "id": 1,
            "method": method,
            "params": params
        }
        r = _http_request(dev, device_port, "POST", "/jsonrpc/0", payload, timeout=timeout, print_request=print_request)
        data = r.json()
        if not isinstance(data, dict):
            raise RPCInvalidError("Unknown RPC error: not a dict")
    
        if isinstance(data, dict) and "error" in data:
            logger.debug("jsonrpc error: %s", data)
            code = data['error'].get('code')
            message = data['error'].get('message', '')
            stacktrace = data['error'].get('data')
            if "UiAutomation not connected" in r.text:
                raise UiAutomationNotConnectedError("UiAutomation not connected")
            if "android.os.DeadObjectException" in message:
                # https://developer.android.com/reference/android/os/DeadObjectException
                raise UiAutomationNotConnectedError("android.os.DeadObjectException")
            if "android.os.DeadSystemRuntimeException" in message:
                raise UiAutomationNotConnectedError("android.os.DeadSystemRuntimeException")
            if "uiautomator.UiObjectNotFoundException" in message:
                raise UiObjectNotFoundError(code, message, params)
            if "java.lang.StackOverflowError" in message:
                raise RPCStackOverflowError(f"StackOverflowError: {message}", params, stacktrace[:1000] + "..." + stacktrace[-1000:])
>           raise RPCUnknownError(f"Unknown RPC error: {code} {message}", params, stacktrace)
E           uiautomator2.exceptions.RPCUnknownError: ('Unknown RPC error: -32001 java.lang.NullPointerException', (False, 50), "java.lang.NullPointerException: Attempt to read from field 'int android.accessibilityservice.AccessibilityServiceInfo.flags' on a null object reference in method 'void uiautomator.InstrumentShellWrapper.setCompressedLayoutHierarchy(boolean)'
    at uiautomator.InstrumentShellWrapper.setCompressedLayoutHierarchy(InstrumentShellWrapper.java:77)
    at com.wetest.uia2.stub.AutomatorServiceImpl.dumpWindowHierarchy(AutomatorServiceImpl.java:273)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)
    at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)
    at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)
    at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)
    at com.wetest.uia2.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:101)
    at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)
    at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
    at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
    at java.lang.Thread.run(Thread.java:1012)")


my-venv/lib/python3.10/site-packages/uiautomator2/core.py:194: RPCUnknownError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions