Skip to content

Uncatchable NullPointerException Crashes Target Process #375

@chaoxi72

Description

@chaoxi72

Description

When hooking Java methods using frida-java-bridge, calling methods on null parameters causes the target process to crash, even when the code is wrapped in a try-catch block. This is unexpected behavior for JavaScript developers and causes production apps to terminate silently.

Reproduction

Java.perform(function () {
    const ArrayList = Java.use("java.util.ArrayList");
    
    ArrayList.add.overload('java.lang.Object').implementation = function (value) {
        try {
            // This crashes the process when value is null
            var className = value.getClass().getName();
            console.log("Class:", className);
        } catch (e) {
            console.log("Exception caught:", e); // Never executed
        }
        return this.add(value);
    };
});

Command:

frida -UF -l script.js

Expected Behavior

The try-catch block should catch the NullPointerException when value is null, log the error message, and allow the application to continue running.

Actual Behavior

The target process terminates immediately:

Process terminated

The exception is never caught, and no error message appears in the console.

Environment

Frida version: 16.2.1
Target platform: Android 6
Script language: JavaScript

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