nikintharan / openhab

Automatically exported from code.google.com/p/openhab
0 stars 0 forks source link

Null check fails #299

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
rule "Null check"
    when System started then
    var Number foo = null
    logDebug("foo", "will check for null" )
    if( foo != null ) {
        logDebug( "foo", "Foo was not null" )
    }
    else {
        logDebug( "foo", "Foo was null" )
    }
end

What is the expected output? What do you see instead?
The expected output is obvious, here is the actual output:

09:39:31.312 DEBUG o.o.m.r.i.engine.RuleEngine[:277]- Executing startup rule 
'Null check'
09:39:31.368 DEBUG org.openhab.model.script.foo[:58]- will check for null
09:39:31.420 ERROR o.o.m.r.i.engine.RuleEngine[:287]- Error during the 
execution of startup rule 'Null check': null

What version of the product are you using? On what operating system?
1.3.0-snapshot

Original issue reported on code.google.com by kristian...@gmail.com on 14 May 2013 at 6:44

GoogleCodeExporter commented 8 years ago
I wouldn't like to bloat my rules with unnecessary variables to workaround this 
bug. How are you (everyone else) avoiding this?

Here's another example:

var Number last_waterpulse_millisec = null

rule "Calculate water flow"
    when Item WaterPulseCounter changed or 
    Time cron "2 0/2 * * * ?" then
    val Number current_value = WaterPulseCounter.state as DecimalType
    val Number current_millis = now.millis
    println( "water flow 1" )
    val State state = WaterPulseCounter.historicState( now.minusMinutes( 2 ) )
    val Number old_value =  if( state instanceof DecimalType ) state as DecimalType else WaterPulseCounter.state as DecimalType
    println( "water flow 2" )
    val Number current_flow_litres = ( old_value - current_value ) * WATERLITERS_PER_PULSE
    println( "water flow 3" )
    if ( last_waterpulse_millisec == null ) { // We do not know from when to measure
        println( "water flow 3.1" )
        postUpdate( WaterFlowSpeed, 0 )
    }
    else {  
        println( "water flow 4" )
        val Number elapsed_time_minutes =  ( current_millis - last_waterpulse_millisec ) / ( 60 * 1000 )
        println( "water flow 5" )
        val Number flowspeed = current_flow_litres /  elapsed_time_minutes
        println( "water flow 6" )
        postUpdate( WaterFlowSpeed, flowspeed )
    }
    last_waterpulse_millisec = current_millis
end

This produces the following output:

water flow 1
water flow 2
water flow 3
10:36:03.190 ERROR o.o.m.r.i.e.ExecuteRuleJob[:77] - Error during the execution 
of rule Calculate water flow
java.lang.NullPointerException: null
        at org.openhab.model.script.lib.NumberExtensions.operator_equals(NumberExtensions.java:73)

Original comment by kristian...@gmail.com on 22 May 2013 at 7:43

GoogleCodeExporter commented 8 years ago

Original comment by kai.openhab on 22 May 2013 at 8:30

GoogleCodeExporter commented 8 years ago
For "Null check" I get the same output on my Systems(Linux VM, Windows 64) 
openHab Version 1.3 demo.
Older Versions sometimes completely ignores Startup Rules at first Startup.

At a second Startup get always: 'Null check': null

> How are you (everyone else) avoiding this?
I use Timers to start more complex Rules later and have to do many test-loops 
to avoid.

I notice these Issue, combined mostly with more complex rules, since openHab 
Version 0.9.
Hope this helps to delimit the Problem a little bit.

Original comment by Helmut.L...@gmail.com on 9 Jun 2013 at 5:02

GoogleCodeExporter commented 8 years ago
Migrated to https://bugs.eclipse.org/bugs/show_bug.cgi?id=423536

Original comment by kai.openhab on 8 Dec 2013 at 2:55