Bug? Resumable sub casting error

mindful

Active Member
Licensed User
B4X:
'Non-UI application (console / server application)
#Region Project Attributes 
    #CommandLineArgs:
    #MergeLibraries: True 
#End Region
Sub Process_Globals
   
End Sub
Sub AppStart (Args() As String)
    StartTest
   
    StartMessageLoop
End Sub
Public Sub StartTest()
    Dim m As Map = Normal1
    LogError("2=" & GetType(m))
    Wait For (Res1) Complete (Result As Object)
    LogError("4=" & GetType(Result))
    m = Result
End Sub
Public Sub Res1() As ResumableSub
    Sleep(0)
    Dim m As Map
    m.Initialize
    LogError("3=" & GetType(m))
    Return m
End Sub
Public Sub Normal1() As Object
    Dim m As Map
    m.Initialize
    LogError("1=" & GetType(m))
    Return m
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Error that it produces:
B4X:
1=anywheresoftware.b4a.objects.collections.Map$MyMap
2=anywheresoftware.b4a.objects.collections.Map$MyMap
3=anywheresoftware.b4a.objects.collections.Map$MyMap
4=anywheresoftware.b4a.objects.collections.Map
main._appstart (java line: 50)
java.lang.RuntimeException: java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1072)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:148)
    at b4j.example.main._appstart(main.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at b4j.example.main.main(main.java:29)
Caused by: java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
    at b4j.example.main$ResumableSub_StartTest.resume(main.java:173)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:135)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:84)
    ... 13 more

As you can see Wait For (Res1) Complete (Result As Object) returns the wrapper instead of the inner object.

If I change it to Result As Map all works well.
 
Top