Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify @Nullable and @Nonnull usage [ci skip] #6095

Merged
15 changes: 15 additions & 0 deletions doc/dev/decisionrecords/Codestyle.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ What to put in Javadoc:
- Is it immutable or should anything be treated as immutable
- Is it a utility class of static methods that should not be instantiated

### Annotations

- On methods:
- Method should be marked as `@Nullable` if they can return null values
- Method parameters should be marked as `@Nullable`.
optionsome marked this conversation as resolved.
Show resolved Hide resolved
- On fields:
- Fields should often be marked as `@Nullable` if they are nullable. If the class
only exposes the field through a simple getter method, using the annotation on field is optional,
but on the getter method it is required.
habrahamsson-skanetrafiken marked this conversation as resolved.
Show resolved Hide resolved

Use of `@Nonnull` annotation is not allowed. It should be assumed methods/parameters/fields
are non-null if they are not marked as `@Nullable`. However, there are places where the
`@Nullable` annotation is missing even if it should have been used. Those can be updated
to use the `@Nullable` annotation.

## JavaScript

As of #206, we
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/opentripplanner/transit/model/package.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ All transit entities must have an ID. Transit entities ar "root" level are consi
roots_.


#### @Nonnull and @Nullable entity fields
#### Non-null and nullable entity fields

All fields getters(except primitive types) should be annotated with `@Nullable` or `@Nonnull`. None
null field should be enforced in the Entity constructor by using `Objects.requireNonNull`,
All fields getters(except primitive types) should be annotated with `@Nullable` if they can return null.
habrahamsson-skanetrafiken marked this conversation as resolved.
Show resolved Hide resolved
Non-nullability of fields should be enforced in the Entity constructor by using `Objects.requireNonNull`,
`Objects.requireNonNullElse` or `ObjectUtils.ifNotNull`. We should enforce this for all fields
required in both GTFS and in the Nordic NeTEx Profile. For enumeration types using a special value
like `UNKNOWN` is preferred over making the field optional.
Expand Down
Loading