Skip to content

support for null-restricted and nullable types #615

@Ladicek

Description

@Ladicek

On the API level, this likely means just adding a method Type.nullness() which returns an enum with 3 values (UNKNOWN, NULLABLE, NULL_RESTRICTED) . However, this also involves changing the serialization format.

Per https://openjdk.org/jeps/8303099:

In Java syntax, a nullness marker is used to indicate this property.

The type Foo! is null-restricted: the value set excludes null.

The type Foo? is nullable: the value set deliberately includes null.

By default, the nullness of the type Foo is unspecified: a null may occur, but we don't know whether its presence is deliberate.

Signature attributes have an updated grammar to allow ! and ? in types, as appropriate. Nullness is not encoded in method and field descriptors.

However, to prevent pollution of fields, a new NullRestricted attribute allows a field to indicate that it does not allow null values.

This suggests that maybe we should add FieldInfo.isNullRestricted(), but let's leave that as an open question for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions