# Strange if/null behaviour

**URL:** <https://community.openhab.org/t/strange-if-null-behaviour/86126>\
**Category:** Scripts & Rules\
**Created:** [November 24, 2019, 6:22am UTC](https://community.openhab.org/t/strange-if-null-behaviour/86126 "2019-11-24T06:22:17Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [November 24, 2019, 4:44pm UTC](https://community.openhab.org/t/strange-if-null-behaviour/86126/3 "2019-11-24T16:44:50Z")

</div>

As Crispin indicated, if you initialize a variable to null, you have to provide the type because they’re has nothing to tell the rules engine what type it is.

> [@jimtng](#):
>
> A separate question: Is there a way to check for the existence of an item without resorting to try / except to catch the exception?

You need to provide more context but I suspect the answer in Rules DSL is no. But I don’t know what ScriptServiceUtil.getItemRegistry.getItem(itemName) returns when the item by that name doesn’t exist. Maybe it just returns null. See [Design Pattern: Associated Items](https://community.openhab.org/t/design-pattern-associated-items/15790) for details.

---

_[View the full topic](https://community.openhab.org/t/strange-if-null-behaviour/86126)._
