apache / royale-compiler

Apache Royale Compiler
https://royale.apache.org/
Apache License 2.0
95 stars 49 forks source link

Binding issue (error-related) #188

Open greg-dove opened 3 years ago

greg-dove commented 3 years ago

Here is an example:

private var _config:SomeTypedObject;

[Bindable]
public function get config():SomeTypedObject
{
    return this._config;
}

public function set config(SomeTypedObject):void
{
    this._config = value;

    // Do something that causes an NPE. In this case, someProperty is null.
    warning = config.someProperty.length == 0;
}

In this scenario, sub properties of config is bound to various fields. Because of the NPE, none of the bindings for this field fire, even though the value is set before the NPE. No error appears in the console or debugger. It's as if it's caught and suppressed at runtime.

Now that I think about it, it may be about how the compiler converts generic [Bindable] fields to dispatch the updated event. I'm betting in this case, if I were to use my own event name and dispatch before the NPE, it would probably work.

Originally posted by @brianraymes in https://github.com/apache/royale-compiler/issues/185#issuecomment-864335780

greg-dove commented 3 years ago

@brianraymes just to be clear:

are you saying that the issue is caused by this code in the setter: warning = config.someProperty.length == 0;

when either the value of 'config' ('this._config') or (this._config.someProperty) is null ?

Did this same code work in Flex?

Otherwise, my first inclination would be to code the setter with null safety, because if you were to set it with null values via regular actionscript it would also error (null value or null value.someProperty).

warning = value && value.someProperty ? value.someProperty.length == 0 : false (or whatever logic makes sense for warning to be true or false in absence of value/ value.someProperty )

However, if you can confirm that this did work in the past as-is in Flex, then I will try to figure it out.

brianraymes commented 3 years ago

In my case, the someProperty was null, not config. If config were null, I would expect the bindings to not show anything.

I can obviously add null protection, but shouldn't there be some sort of exception thrown? Some sort of way to determine why it is failing at runtime, at least with a debug build? Other properties of config were not null, and were expected to be displayed, or at least an NPE to let me know of the failure. I keep running into issues like this where views stop processing data and just appear blank with no understandable reason as to why.

Another simple example, but unrelated to binding, is using the Jewel VirtualList without a ListPresentationModel with rowHeight set. VirtualList requires the rowHeight for layout, but doesn't error in any way without it. It simply shows up blank with no exception. These kinds of issues have been cropping up a bit for me as I have been building with Royale, and seem to waste quite a bit of time before I figure out how/where/why.

I will have to get back to you on testing with Flex. I'll try to set up an example in the coming days to verify.