Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding issue (error-related) #188

Open
greg-dove opened this issue Jun 20, 2021 · 2 comments
Open

Binding issue (error-related) #188

greg-dove opened this issue Jun 20, 2021 · 2 comments
Assignees

Comments

@greg-dove
Copy link
Contributor

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 #185 (comment)

@greg-dove
Copy link
Contributor Author

@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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants