sushihangover / as3-commons

Automatically exported from code.google.com/p/as3-commons
1 stars 0 forks source link

org.as3commons.lang.ClassUtils.forName() fails when getting declaring type of method in RSL #46

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Load an RSL swf via URLLoader, and call 
ByteCodeType.fromByteArray(loader.data, tempDomain) where loader refers to the 
URLLoader instance and temp domain is a domain you created.
2. Get the ByteCodeType for some class in that RSL and iterate through its 
methods, tracing their declaringType:
      var type:ByteCodeType = ByteCodeType.forName(className,tempDomain);
      for each(var j:ByteCodeMethod in type.methods){
           trace(j.declaringType);
      }
3. Enjoy the resulting stacktrace:

TypeError: Error #1009: Cannot access a property or method of a null object 
reference.
    at org.as3commons.reflect::JSONTypeProvider/getType()[C:\projects\as3-commons\as3-commons-reflect\src\main\actionscript\org\as3commons\reflect\JSONTypeProvider.as:44]
    at org.as3commons.reflect::Type$/forClass()[C:\projects\as3-commons\as3-commons-reflect\src\main\actionscript\org\as3commons\reflect\Type.as:171]
    at org.as3commons.reflect::Type$/forName()[C:\projects\as3-commons\as3-commons-reflect\src\main\actionscript\org\as3commons\reflect\Type.as:147]
    at org.as3commons.reflect::Method/get declaringType()[C:\projects\as3-commons\as3-commons-reflect\src\main\actionscript\org\as3commons\reflect\Method.as:84]

If you dig deeply enough, the root issue is that 
tempDomain.getDefinition(className) is returning null in 
org.as3commons.lang.ClassUtils.forName().

I can work around this issue by loading RSLs via Loader and calling 
ByteCodeType.fromLoader instead.

Original issue reported on code.google.com by t...@nthsense.net on 24 Mar 2011 at 7:16

GoogleCodeExporter commented 8 years ago
I have overriden the declaringType getters in the appropriate -bytecode classes 
to return a ByteCodeType instead of Type instance, this should avoid the 
ClassUtils.forName() call. applicationDomain.getDefinition seems a bit flaky 
when it comes to types loaded into separate applicationdomains (so other than 
the ApplicationDomain.currentDomain), so this may even be a flashplayer bug.

Original comment by ihatelivelyids on 26 Mar 2011 at 10:48