Skip to content

JSpecify JDK models: System.getProperty(String, String) with a non-null default is reported as @Nullable #2061

Closed

Description

@ThoSap

With JSpecifyExperimental, NullAway reports the result of System.getProperty(String, String) as @Nullable, also when the default value is a non-null literal.
The same happens for Properties.getProperty(String, String).

Example

import java.util.Properties;
import org.jspecify.annotations.NullMarked;

@NullMarked
class Example {
    static int systemProperty() {
        String value = System.getProperty("user.home", "");
        return value.length();
    }

    static int propertiesProperty(Properties properties) {
        String value = properties.getProperty("key", "");
        return value.length();
    }
}

With -XepOpt:NullAway:JSpecifyMode=true and -XepOpt:NullAway:JSpecifyExperimental=true:

Example.java:8: error: [NullAway] dereferenced expression 'value' is @Nullable
        return value.length();
                    ^
Example.java:13: error: [NullAway] dereferenced expression 'value' is @Nullable
        return value.length();
                    ^

Without JSpecifyExperimental, NullAway reports nothing.

Cause

The JSpecify JDK models declare a @Nullable return type and a @Nullable default value, because JSpecify has no @PolyNull:

The result is null only when the property is missing and the default value is null.
So the return value has the same nullness as the default value.

Suggestion

#1813 added @PolyNull library models for Optional.orElseGet and Map.computeIfAbsent, for the same kind of false positive (#1616).
The two methods above could get the same model in POLY_NULL_LOCATIONS: the default value parameter and the return value as @PolyNull locations.

Versions

  • NullAway 0.14.3
  • Error Prone 2.51.0
  • JDK 25.0.4 (Amazon Corretto)

Activity

  1. added a commit that references this issue on Oct 24, 2026
    a856510
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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