# Is it safe to expect NotNull / Nullable annotations to always be present ? (Added to fields by Kotlin compiler)

**URL:** <https://discuss.kotlinlang.org/t/is-it-safe-to-expect-notnull-nullable-annotations-to-always-be-present-added-to-fields-by-kotlin-compiler/235>\
**Category:** Uncategorized\
**Created:** [May 15, 2015, 1:14am UTC](https://discuss.kotlinlang.org/t/is-it-safe-to-expect-notnull-nullable-annotations-to-always-be-present-added-to-fields-by-kotlin-compiler/235 "2015-05-15T01:14:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbygrave](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/rbygrave/32/1433_2.png) [@rbygrave](https://discuss.kotlinlang.org/u/rbygrave)\
**Post date:** [May 15, 2015, 1:14am UTC](https://discuss.kotlinlang.org/t/is-it-safe-to-expect-notnull-nullable-annotations-to-always-be-present-added-to-fields-by-kotlin-compiler/235/1 "2015-05-15T01:14:39Z")

</div>

I'm pondering using java reflection to look for the NotNull / Nullable annotations that the kotlin compiler adds.&nbsp;&nbsp;The purpose is to implicitly determine properties on ORM entity beans that must not be not null db columns.

Is it safe to expect those annotations to always be present (always added to the associated fields by the Kotin compiler)?&nbsp;&nbsp;

Thanks, Rob.

Example:

&nbsp;

```kotlin
Size(max = 100)
public var subject: String? = null;
```

&nbsp;&nbsp;

```kotlin
// NotNull ... no need to explictly add separate NotNull annotation
```

&nbsp;

```kotlin
//           because Kotlin compiler will always add one for us
```

```

```

```

```

```

```

```

```

```
 

```kotlin
Size(max = 100)
public var code: String = "";
```

```

```

```

```
```
&nbsp;

&nbsp;&nbsp;// access flags 0x2 &nbsp;&nbsp;private Ljava/lang/String; subject &nbsp;&nbsp;@Ljavax/validation/constraints/Size;(max=100) // invisible &nbsp;&nbsp;**_@Lorg/jetbrains/annotations/Nullable;()_** // invisible

&nbsp;&nbsp;// access flags 0x2  
&nbsp;&nbsp;private Ljava/lang/String; code  
&nbsp;&nbsp;@Ljavax/validation/constraints/Size;(max=100) // invisible  
&nbsp;&nbsp;**_@Lorg/jetbrains/annotations/NotNull;()_** // invisible

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [May 15, 2015, 12:18pm UTC](https://discuss.kotlinlang.org/t/is-it-safe-to-expect-notnull-nullable-annotations-to-always-be-present-added-to-fields-by-kotlin-compiler/235/2 "2015-05-15T12:18:11Z")

</div>

As your listing mentions, @NotNull is not visible through reflection, because its retention policy is CLASS

---

<div class="post-metadata">

**Author:** ![jayson.minard](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jayson.minard/32/1434_2.png) [@jayson.minard](https://discuss.kotlinlang.org/u/jayson.minard)\
**Post date:** [June 12, 2015, 8:23pm UTC](https://discuss.kotlinlang.org/t/is-it-safe-to-expect-notnull-nullable-annotations-to-always-be-present-added-to-fields-by-kotlin-compiler/235/3 "2015-06-12T20:23:27Z")

</div>

I think with JetValueParameter you had a type of "?" but that is deprecated.&nbsp;&nbsp;Don't remember clearly if that was always accurate.

No plan @andrey for making this visible to reflection.&nbsp;&nbsp;I was just working on a data binder for JSON to replace the front-end of Jackson (still using core) to do smarter binding with Kotlin.&nbsp;&nbsp;Knowing if something is nullable would let it know better if there is an error or not before setting a value.&nbsp;&nbsp;Which could let it pick different constructors, or try to determine if there is one with a default value, etc.

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [June 15, 2015, 3:25pm UTC](https://discuss.kotlinlang.org/t/is-it-safe-to-expect-notnull-nullable-annotations-to-always-be-present-added-to-fields-by-kotlin-compiler/235/4 "2015-06-15T15:25:07Z")

</div>

Yes, it will be available once we roll out the full Reflection API
