Tencent/tinker · error · IllegalArgumentException

file is null.

Error message

file is null.

What it means

Thrown by the Dex(File) constructor when the File argument is null. This is a plain argument-contract failure before any I/O happens: the library refuses to guess what to load. All other constructors (InputStream, byte[], ByteBuffer) bypass this check.

Source

Thrown at third-party/aosp-dexutils/src/main/java/com/tencent/tinker/android/dex/Dex.java:129

    }

    /**
     * Creates a new dex buffer of the dex in {@code in}, and closes {@code in}.
     */
    public Dex(InputStream in) throws IOException {
        loadFrom(in);
    }

    public Dex(InputStream in, int initSize) throws IOException {
        loadFrom(in, initSize);
    }

    /**
     * Creates a new dex buffer from the dex file {@code file}.
     */
    public Dex(File file) throws IOException {
        if (file == null) {
            throw new IllegalArgumentException("file is null.");
        }

        if (FileUtils.hasArchiveSuffix(file.getName())) {
            ZipFile zipFile = null;
            try {
                zipFile = new ZipFile(file);
                ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
                if (entry != null) {
                    InputStream inputStream = null;
                    try {
                        inputStream = zipFile.getInputStream(entry);
                        loadFrom(inputStream, (int) entry.getSize());
                    } finally {
                        if (inputStream != null) {
                            inputStream.close();
                        }
                    }
                } else {

View on GitHub (pinned to 1b7ea02c23)

Solutions

  1. Check the upstream step that produced the File — it is null because a download, unzip, or path resolution failed; fix that first.
  2. Add an explicit null/exists() check before constructing Dex and fail with a descriptive message naming the expected path.
  3. If null is a legitimate state in your flow, branch to a different code path instead of relying on the constructor to validate.

Example fix

// before
Dex dex = new Dex(maybeNullFile);

// after
if (file == null || !file.exists()) {
    throw new IllegalStateException("dex input missing: " + expectedPath);
}
Dex dex = new Dex(file);
Defensive patterns

Strategy: validation

Validate before calling

if (file == null) throw new IllegalArgumentException("dex file path unresolved: " + describedSource);

Prevention

When it happens

Trigger: Calling new Dex((File) null) or new Dex(file, MUTF_8?) style overloads with a null File — typically the result of a failed lookup (e.g. zip extraction returned null, a path variable never set) passed straight into the constructor.

Common situations: Patch/build scripts where the dex path comes from an environment variable, gradle task input, or a previous step that silently produced no file; refactorings that changed the variable being passed.

Related errors


AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14). Data as JSON: /api/errors/f569f14a705eab75. Report an issue: GitHub.