There is a good reason for copy constructors and Clone() methods. It is just plain wrong to attempt to clone an object by constructing a new one and then setting its public properties that you know about. You have absolutely no way to guarantee that you know enough to clone an object that way -- because in the general case you don't know enough. You MUST use a copy constructor or a Clone() method.
Neither of those methods exist for an expandable object being used as an expandable property. There is, however, a functional equivalent -- create a new instance of the indicator and call the expandable property's get() method. That is guaranteed to return a valid instance of the expandable object. At that point you can set the new object's public properties to anything you like. The important point is that you MUST use get(), not operator new, to clone such an object.
The following code shows the bug. The comments at the top contain detailed instructions for reproducing the problem. If they are not clear enough, let me know and I'll improve whatever is not clear enough. I do not think the file requires anything from my environment. If I overlooked some dependency, let me know and I'll fix it.
The general idea is:
- Create a chart template that includes the test indicator
- Create a new chart using that template
- As part of creating that chart, NT will both make a bogus clone of the object, and then set the bogus clone into an instance of the indicator
Comment