Using =' instead of '= for null oref checks
objectscriptQuality release
Id
OS0060
Rule type
Code Smell
Severity
Blocker
Blocker
SQALE characteristic
- Reliability
- Instruction
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.

