Weird variable behaviour

I’m having problems with a simple rule I want to use to change the volume on my receiver using a python script.
The issue I’m having is with the volume variable. I read it from the receiver and print it to the log (-47). However when I try to use it in my if-statement I get a null pointer. How is this possible??

rule NadVolume
   Item nadVolume received command
   try {
       var Number volume = executeCommandLine("python/ volume ?", 2000)
       logInfo("volume", "volume changed " + volume)
       if(volume < 7 && volume > -99) {
           switch (receivedCommand){
               case 1: volume = volume + 1
               case 2: volume = volume - 1
       executeCommandLine("python/ volume " + volume)
   finally {

from the log:

2016-09-01 21:12:39.166 [INFO ] [rg.openhab.model.script.volume] - volume changed -47
2016-09-01 21:12:40.189 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'NadVolume': Could not invoke method: org.openhab.model.script.lib.NumberExtensions.operator_lessThan(java.lang.Number,java.lang.Number) on instance: null

executeCommandLine returns a String, not a Number. You must convert the String to a Number before you can use it as such.

var Number volume = new Integer(executeCommandLine("python/ volume ?", 2000))

Ahh, naturally. Thanks.
The error wasn’t very helpful though. There is a huge difference between a type error and a null pointer.

Unfortunately all type errors are null pointer errors in the Rules DSL. There are lots of good technical reasons for why that is the case, with the primary one being that the Rules DSL isn’t strongly typed so type isn’t determined until runtime and when you have the wrong type the stuff that does the automatic type determination and conversion for you returns null if it can’t cast it. Hence the null pointer exceptions.

I guess it kind of makes sense. Knowing this will make future debugging easier though.
Thanks for helping a noob :slight_smile: