Skip to content

Commit

Permalink
Update Null Annotations Conventions (openhab#740)
Browse files Browse the repository at this point in the history
Signed-off-by: Wouter Born <eclipse@maindrain.net>
  • Loading branch information
wborn authored and Confectrician committed Jul 12, 2018
1 parent 0987df4 commit ca77e5b
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions developers/development/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,32 @@ There will be a warning in the IDE for this check, but that is fine.
For private methods or methods in an internal package the annotations are respected and additional `null` checks are omitted.

To use the annotations, every bundle must have an **optional** `Import-Package` dependency to `org.eclipse.jdt.annotation`.
Classes should be annotated by `@NonNullByDefault` and return types, parameter types, generic types etc. are annotated with `@Nullable` only.
Classes should be annotated with `@NonNullByDefault`:

```java
@NonNullByDefault
public class MyClass(){}
```

Return types, parameter types, generic types etc. are annotated with `@Nullable` only.
The annotation should be written in front of the type.

Fields should be annotated like this:

```java
private @Nullable MyType myField;
```

Methods should be annotated as follows:

```java
private @Nullable MyReturnType myMethod(){};
```

Fields that get a static and mandatory reference injected through OSGi Declarative Services can be annotated with

```java
@NonNullByDefault({})
private MyService injectedService;
private @NonNullByDefault({}) MyService injectedService;
```

to skip the nullevaluation for these fields.
Expand Down

0 comments on commit ca77e5b

Please sign in to comment.