IF NOT MyMethod(foo) THEN does not work (A warning)

Posted by jmls on 28-Jun-2009 14:35

I know it's hard to beleive. I have spent all day debugging some code and have finnaly found the culprit.  This is the offending code:

/* ==========================================================================    LoadPhoneLine    ==========================================================================*/   METHOD PUBLIC LOGICAL LoadPhoneLine(p_PhoneLineGUID AS CHAR):     DEF BUFFER PhoneLine FOR PhoneLine.         FIND PhoneLine WHERE PhoneLine.PhoneLineGUID EQ p_PhoneLineGUID NO-LOCK NO-ERROR.                          IF NOT AVAIL PhoneLine THEN     DO:       ASSIGN THIS-OBJECT:PhoneLineGUID = ""              THIS-OBJECT:PhoneNumber   = "".     END.         ELSE     DO:                            ASSIGN THIS-OBJECT:PhoneLineGUID = p_PhoneLineGUID              THIS-OBJECT:PhoneNumber   = PhoneLine.PhoneNumber.     END.         RETURN AVAIL PhoneLine.   END METHOD.

METHOD PUBLIC CHAR GetPhoneLineConfig (p_PhoneLineGUID AS CHAR):      DEF BUFFER PhoneLine     FOR PhoneLine.           IF NOT THIS-OBJECT:LoadPhoneLine(p_PhoneLineGUID) THEN .      DO:       MessageManager:LogError(SUBSTITUTE("No Phoneline [&1] Exists",p_PhoneLineGUID)).       RETURN "".      END.

     RETURN "stuff".    

END METHOD.

The method GetPhoneLineConfig always returns "" . However, if I change it to read

METHOD PUBLIC CHAR GetPhoneLineConfig (p_PhoneLineGUID AS CHAR):      DEF BUFFER PhoneLine     FOR PhoneLine.

     DEF VAR Check AS LOGICAL NO-UNDO.

     ASSIGN Check = THIS-OBJECT:LoadPhoneLine(p_PhoneLineGUID).

          IF NOT Check THEN      DO:       MessageManager:LogError(SUBSTITUTE("No Phoneline [&1] Exists",p_PhoneLineGUID)).       RETURN "".      END.

     RETURN "stuff".         

then "stuff" is returned.

As mentioned, I spent most of the afternoon finding this piece of code. I checked. I double-checked. However, no demo code I produced gave the same problem.

Can you spot the problem ?

(Hint. It's empty)

All Replies

Posted by Peter Judge on 29-Jun-2009 08:14

Can you spot the problem ?

(Hint. It's empty)

Ouch. Or should that be "d'oh". Or maybe, as my good friend Bill would say "out, damn'd spot!".

I really dislike these kinds of bugs, both for the time they take to find and for making me question my sanity (more than usual, I mean).

-- peter

Posted by GregHiggins on 01-Jul-2009 10:08

Yet another good reason for putting the DO on the same line as the THEN .

I don't like the default formatting ^A^I in Architect, and I'd specifically like to change this behavior.

This thread is closed