Using =' instead of '= for null oref checks

objectscriptQuality release 
1.0.0
Id 
OS0060
Rule type 
Code Smell
Severity 

Blocker

Blocker
SQALE characteristic 
  • Reliability
    • Instruction
Tags 
probable-bug, trap
Remediation function 
Constant/issue
Remediation cost 
5min

Consider this code:

    Class Fubar
    {
    ClassMethod m(someArg as Some.Class)
    {
        if (someArg =' "") {
            w "my argument was a null oref", !
        }
    }
    }

There is a trap in this code.

ObjectScript allows spaces between the unary negation operator (that is, ') and its argument: 'a and ' a are the same.

Which means that another way to write the code above would be:

    Class Fubar
    {
    ClassMethod m(someArg as Some.Class)
    {
        if (someArg = '"") { // <-- NOTE WHERE THE NEGATION IS
            w "my argument was a null oref", !
        }
    }
    }

which means the code turns out to be, ultimately:

    Class Fubar
    {
    ClassMethod m(someArg as Some.Class)
    {
        if (someArg = 1) {
            w "my argument was a null oref", !
        }
    }
    }

And that is quite different from testing for a null object reference!

This is very probably a typo.