Code highlighting

Wednesday, June 27, 2007

A bug in validation of methods' access modifiers and class abstract modifier

While testing the new feature of Tabax plugins today, discovered a bug in access modifiers validation.

It is performed only at compile time.
Which means, that if the compiler doesn't know what object the method belogns to, than the validation is skipped.
And you can run protected and private methods from whereever your code is executed.

Here is a simple example: (press cancel in the dialogs, otherwise you will get a RunTime error, because the method pack is not implemented in RunBase)

static void tutorial_AccessModifiersError(Args _args)
{
    Object runBaseObj;
    SysDictClass dictClass;
    ;
    runBaseObj = RunBase::makeObject(classNum(RunBase));
    runBaseObj.setInPrompt(true);
    runBaseObj.promptPrim();
    runBaseObj.setInPrompt(false);

    dictClass = new SysDictClass(classNum(RunBase));
    dictClass.callObject(methodStr(RunBase, promptPrim), dictClass.makeObject());
}

setInPrompt and promptPrim are both private methods. so they should not be allowed to be called this way.

The same thing can be achived by using DictClass.

The funny thing is:
while writing a test example for this post, I stumbled upon another bug - now it's about the abstract modifier of a class.

You all are probably aware that RunBase is an abstract class and cannot be initialized.
Well, in the example I showed this is done using 2 methods again :)

I guess someone should register these with Microsoft.

3 comments:

  1. it's easier using an object-handle to call private or protected methods

    object o;

    o = yourObject;

    o.protectMethod();
    o.privateMethod();

    ReplyDelete
  2. "I guess someone should register these with Microsoft."

    Consider it registered, I am a new hire in the Microsoft Dynamics Axapta team and have been following your blog to get up to speed with my new team. I am afraid I still don't know enough to know if this is an issue we can/want to/should fix but at least I can make sure people who do know hear about it.

    Looking forward to more of your posts!
    Angel MS Microsoft Dynamics

    ReplyDelete
  3. Hey, Angel MS Microsoft Dynamics. :)

    Could you please e-mail me at
    ivan.kashperuk@gmail.com

    I have a question I want to ask you.

    ReplyDelete

Please don't forget to leave your contact details if you expect a reply from me. Thank you