Skip to content

Wrong @Nullable on array access when element has @Nullable-annotated generic #1417

@JarvisCraft

Description

@JarvisCraft

Description

When using latest NullAway (0.12.15) in JSpecify mode, accessing an array element seems to misplace it, e.g. for Container<@Nullable Void>[] arr, arr[0] is wrongly treated as @Nullable.

Minimal reproducing example

package ru.snowone2026.pportnov.errorprone;

import org.jspecify.annotations.Nullable;

class NullableGenericInArray {

    Container<@Nullable Void> partOf(Container<@Nullable Void>[] tasks) {
        return tasks[0];
    }

    interface Container<T extends @Nullable Object> {
    }
}

Expected behaviour: successful compilation

Actual behaviour: compilation error:

NullableGenericInArray.java:6: error: [NullAway] returning @Nullable expression from method with @NonNull return type
        return tasks[0];
        ^
    (see http://t.uber.com/nullaway )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugjspecifyRelated to support for jspecify standard (see jspecify.dev)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions