Bug? List bug - uninitialised list incorrectly reported - its a bit complicated but look closely at the example.

JackKirk

Well-Known Member
Licensed User
Longtime User
This started out on:
https://www.b4x.com/android/forum/threads/solved-maddening-list-bug.134405/

The following example needs to be looked at closely:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Public good_list As List
    Public good_value As String
    Public bad_list As List
    Public bad_value As String
    Public obj_timer As Timer
End Sub

Sub AppStart (Args() As String)
    good_list.Initialize
    good_value = "good"
    good_list.Add(good_value)
 
    obj_timer.Initialize("event_obj_timer", 1)
    obj_timer.Enabled = True
 
    StartMessageLoop

End Sub

Sub event_obj_timer_Tick
    obj_timer.Enabled = False
 
    Log(good_list.IsInitialized)
 
    Sleep(1)
 
    If good_list.Get(0) = "whatever" Then                 '<<<<<<This is line 34 which is reported as bombing
 
    End If
 
    If bad_list.Size > 0 Then                            '<<<<<<This is the real problem
        Log("???")
    End If

End Sub
The log is:
Waiting for debugger to connect...
Program started.
true
Error occurred on line: 34 (Main)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4a.objects.collections.List.getSize(List.java:134)
at b4j.example.main$ResumableSub_event_obj_timer_Tick.resume(main.java:146)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.keywords.Common$2$1.run(Common.java:1035)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:119)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:170)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at b4j.example.main.main(main.java:29)
Note: the error is reported as on line 34 but is actually on line 38

Sounds trivial? - not when you are dealing with a larger bit of code and the distance between reported and actual is considerable.

Everything is reported properly when the sleep statement is removed - so it is to do with resumable subs.

I should add that I tried it with maps too - with the same problem.
 

Attachments

  • listbug.zip
    893 bytes · Views: 129
Top