XMLListCollection: exception in constructor
Test case code:
i2.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.apache.org/royale/mx"
width="600" height="400" >
<fx:Script>
<![CDATA[
// this works
// import mx.collections.XMLListCollection;
// static public var xmllc:XMLListCollection=new XMLListCollection();
// this doesn't
import testglob;
public var h:String = testglob.Hello;
]]>
</fx:Script>
<mx:Label text="{xmllc.toString()}"/>
</mx:Application>
testglob.as:
package
{
import mx.collections.XMLListCollection;
[Bindable]
public class testglob
{
static public var Hello:String = "Hello";
static public var Devices:XMLListCollection=new XMLListCollection();
}
}
When the XMLListCollection is initialised in the mxml file, everything is fine and the initialisation is successful.
When it's initialised by importing the testglob.as class, I get an exception:
Uncaught TypeError: Cannot read property 'createUID' of undefined
at mx.collections.XMLListAdapter.set__source (XMLListAdapter.js:615)
at new mx.collections.XMLListAdapter (XMLListAdapter.js:37)
at mx.collections.XMLListCollection.set__source (XMLListCollection.js:362)
at new mx.collections.XMLListCollection (XMLListCollection.js:37)
at testglob.js:50
On the face of it it seems a bit like the other XML bug I reported a couple of days ago, where the framework is calling an internal function that seems not to be there. So it's either never loaded (it looks as if it is) or something is treading on it. Or something else completely different.
I am running the nightly build on OSX big sur, log follows:
Using Royale Compiler codebase: /Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/bin/../..
Using Royale SDK: /Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/bin/../..
MXMLJSC
+royalelib=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/bin/../../frameworks
-sdk-js-lib=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/bin/../../frameworks/js/Royale/generated-sources
-source-path
./src/
-compiler.services=src/services-config.xml
-locale=en_US,es_ES
-allow-source-path-overlap=true
-source-path=./src/locale/{locale}
-compiler.fonts.managers=flash.fonts.AFEFontManager
-target-player=32.0.0
-compiler.optimize=false
-define+=config::DEBUG,true
-define+=goog::DEBUG,false
+configname=flex
-compiler.targets=JSRoyale
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/libs/royale-typedefs-gcl-0.9.8-SNAPSHOT-typedefs.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Core-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Language-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/HTML-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Basic-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Collections-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Binding-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Graphics-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/MXRoyale-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/DragDrop-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Express-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Effects-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Formatters-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Charts-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Network-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Reflection-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/XML-0.9.8-SNAPSHOT-js.swc
-link-report=./report.xml
-output
bld/index.swf
--
src/i2.mxml
Dec 13, 2020 3:24:40 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: /Users/jim.page/Documents/git/flexportal/bin/js-debug/mx/core/UIComponent.js:3357: WARNING - Suspicious code. This code lacks side-effects. Is there a bug?
} else if ((this.mx_core_UIComponent__toolTip == null || this.mx_core_UIComponent__toolTip == "") && this.mx_core_UIComponent__toolTipBead != null) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Dec 13, 2020 3:24:40 AM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 0 error(s), 2 warning(s), 98.2% typed
The project 'i2' has been successfully compiled and optimized.
40.123570103 seconds
Some further info. I placed a breakpoint just before the line causing the exception in both cases. In the version that works, this.org.apache.royale.utils looks like this:

In the broken version it looks like this:

So there are a lot fewer imports happening. Is my issue that I should be importing something into the as file that i am not?
This may be a problem with static initializers. I haven't tried, but as a workaround maybe use a getter with lazy initialization for Devices.
In other words, try replacing
static public var Devices:XMLListCollection=new XMLListCollection();
with
static private var _Devices:XMListCollection; static public function get Devices():XMLListCollection() { if (!_Devices) _Devices = new XMLListCollection(); return _Devices; }
Just confirming that I able still able to reproduce this issue with the latest compiler. It does appear to be a static dependency ordering issue. org.apache.royale.utils.UIDUtil is not being loaded before mx.collections.XMLListAdapter, as it should when mx.collections.XMLListCollection is accessed from a static variable.
I assume that the goog.addDependency() calls that we generate need to be tweaked a bit to fix this. However, I am not super familiar with that part of the compiler code, so I don't have a plan for how to proceed at this time.
Yeah. This is a known problem.
Currently it's only possible to reliably use native types in static initializers. Static initializers are evaluated when the JS file loads. The only way to get that to work with the current system is to ensure that the dependencies load first. There are cases where it's impossible to resolve that because you can have A which references B and B which references A.
One potential solution which I mentioned in the past is to collect all non-native static initializers collected and loaded after all the other files. I think @aharui might have had a different solution.