Skip to content

[🚀 Feature]: JSpecify Nullness annotations for Java #14291

Closed
@mk868

Description

@mk868

Feature and motivation

I suggest adding JSpecify Nullness annotations to the Selenium framework code.
These annotations allow you to specify which parameters and return values can be null.
I'm aware that information about potential null values are already placed in the JavaDoc, but using annotations will be transparent to IDEs and static code analyzers.
This will give developers better exposure of potential problems with their code in order to avoid NullPointerExceptions.

Using annotations will also improve interoperability with Kotlin.

Links:

Usage example

The annotated method would look like this:

// ...

import org.jspecify.annotations.Nullable;

public interface WebElement extends SearchContext, TakesScreenshot {
// ...

@Nullable String getAttribute(String name);

// ...
}

Then the IDE/static code analyzer will display a warning about unsafe code:

var element = webDriver.findElement(By.tagName("img"));
var cssClasses = element.getAttribute("class").split(" "); // warning here, possible NullPointerException

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-enhancementSomething could be betterR-help wantedIssues looking for contributions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions