Exception in rules after restart

I have a weird problem regarding the rules. Since I started openHAB (on a raspberry pi) the last time, I’ve got a bunch of exceptions. E.g.:

[e.x.l.lazy.LazyLinkingResource] - resolution of uriFragment 'xtextLink_::0.2.4.2.0.0.0.7.7::0::/1' failed.
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lorg.eclipse.emf.common.notify.Adapter;

or

[.x.c.types.util.TypeReferences] - Couldn't find JvmType for name 'org.openhab.model.script.lib.NumberExtensions' in context org.eclipse.xtext.xbase.resource.XbaseResource@1313a0c uri='my.rules'
java.lang.NullPointerException: null

Everything was running ok before so there has not been any error within the rules. I later thought of maybe this comes from not loaded all items when the rules are invoked, so I did following:

  1. stopped openHAB
  2. removed the rules
  3. started openHAB
  4. waited until system has been started
  5. deployed rule after rule with a few seconds of delay

After this, I haven’t got any exception so far.
Did anyone experience a similiar problem? Is there a way to avoid the manuell deployment of the rules?

I have seen this on a very intermittent basis on a Pi 2–maybe in one startup out of twenty or so. I suspect there is some sort of low-level dependency in the various startup threads which has not been controlled for, but is only exposed in a small subset of test cases because it is essentially a timing bug, ergo also likely a “Heisenbug” - if you instrument to catch it, you cannot because the instrumentation affects thread pacing and the bug does not occur. (Nasty problem)

Usually I just control-C the openhab process and restart it, giving a bit of time for all the jvm threads to terminate after the control-C. Basically means that I watch the console at OH startup for this pattern.

You could (in a separate console window), use “touch” on the rules directory after this pattern occurs to force OH to reread the rules. I have done this also and it has worked. You do pretty much have to wait for the spewing messages to stop before doing the “touch”, so it’s just easier to watch the console for a few seconds at startup and control-C if necessary.