asOid() return is an invalid object

For questions and postings not covered by the other forums
Stokes
Posts: 66
Joined: Wed Oct 13, 2010 2:06 pm
Location: QLD, Australia

asOid() return is an invalid object

Postby Stokes » Tue Aug 01, 2017 11:25 am

I have just realised that the asOid() method always returns an object even if it is not valid

Code: Select all

vars currOid : String; jadeSkin : JadeSkin; begin currOid := "525.1"; //This is an invalid oid. jadeSkin := currOid.asOid().JadeSkin; if not app.isValidObject(jadeSkin) then write "**INVALID OBJECT**"; endif; if jadeSkin <> null then write "but this is also not null????"; endif; end;
This to me doesn't make any sense. Why does Jade not just return a null like all other methods? For example calling getAtKey would return a null not an invalid object.

So, if you have any code that is just doing a null check after an asOid this is pointless because there is always going to be an object after using the asOid method, whether it is valid or not is the only check you should be doing.

I feel as though this is a fault but would be interested to know if others agree before I log this in Parsys.

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: asOid() return is an invalid object

Postby BeeJay » Tue Aug 01, 2017 4:09 pm

I wouldn't necessarily view this as a fault any more than any other method which returns an object reference which may or may not refer to an invalid object.

eg: someObject := someOtherObject.someMethodThatReturnsAnObject();

Also, given that using "asOid/asObject" in regularly executed production code is somewhat frowned upon, one shouldn't really store object references as strings, I'm not sure that you'll get much traction on changing this behaviour. I suspect that changing this behaviour could also break 'fixup script' code that other developers have written that is expecting an invalid object reference rather than a null object reference to be returned from the "asOid/asObject" method.

Cheers,
BeeJay.

JohnP
Posts: 73
Joined: Mon Sep 28, 2009 8:41 am
Location: Christchurch

Re: asOid() return is an invalid object

Postby JohnP » Tue Aug 01, 2017 6:38 pm

The asOid() method doesn't return an object, it returns an object reference. Whether it is valid, invalid or null depends on the string you pass in to it. If you pass in "0.0", the reference returned will be null.

There is a big difference between a null object reference and an invalid object reference. A null reference refers to class 0 and instance 0. An invalid one looks proper on the surface (like 525.1 for example), but there is no object in the database with that oid.

Stokes
Posts: 66
Joined: Wed Oct 13, 2010 2:06 pm
Location: QLD, Australia

Re: asOid() return is an invalid object

Postby Stokes » Wed Aug 02, 2017 12:00 pm

Thanks a lot for clearing that up for me. Makes a lot more sense now.

The reason we use asOid() is because of JHP, we use the OID to store certain objects against the session.

When we are checking if an object has been deleted I just need to make a change away from a null check to an isValidObject or make sure the OID is cleared from the session after it has been deleted.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 44 guests