B4J Question StringIndexOutOfBoundsException when not doing string operations

JackKirk

Well-Known Member
Licensed User
Longtime User
I am doing some fiddling with the Windows routing table, the problem occurs in this code:
B4X:
Private wrk_sh As Shell
 
'For all connections found...
For wrk_ptr = 0 To Gen_load_balancing_connections.Size - 1

    'Set up shell to set adapter metric of connection to 5
    wrk_args.Clear
    wrk_args.Add("/c")
    wrk_args.Add("powershell.exe set-netroute -interfacealias '" & Gen_load_balancing_connections.Get(wrk_ptr) & "' -routemetric 5")
       
    wrk_sh.InitializeDoNotHandleQuotes("Event_shell2", "cmd.exe", wrk_args)
                                   
    Try
                                       
        'Run shell with a 10 min timeout
        wrk_sh.Run(600000)
       
        'Wait for shell to terminate...
        Wait For Event_shell2_ProcessCompleted(Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
       
        If Success And ExitCode = 0 Then

        Else
       
            wrk_sms = wrk_sms & CRLF & Gen_load_balancing_connections.Get(wrk_ptr) & " - error setting adapter metric"
           
            wrk_log = wrk_log & Gen_crlf & "Error after shell wait (setting adapter metric)..."
                                                   
            wrk_log = wrk_log & Gen_crlf & "Success: " & Success & Gen_crlf & "ExitCode: " & ExitCode & Gen_crlf & "StdOut: " & StdOut & Gen_crlf & "StdErr: " & StdErr
   
        End If
                   
    Catch
       
        wrk_sms = wrk_sms & CRLF & Gen_load_balancing_connections.Get(wrk_ptr) & " - error setting adapter metric"
       
        wrk_log = wrk_log & Gen_crlf & "Error at shell run (setting adapter metric)..."
   
    End Try

Next
When running in Debug mode, the error I am getting is:

But line 644 is:

If Success And ExitCode = 0 Then

If I put some nonsense code such as:
B4X:
If Success And ExitCode = 0 Then
    Private junk As Int = wrk_ptr
    wrk_ptr = junk
Else
It then fails at:

wrk_ptr = junk

I have tried all sorts of alternatives but am still generating this error.

Having run out of ideas I implore someone to tell me what is going on.

Thanks in anticipation...
 
Last edited:

JackKirk

Well-Known Member
Licensed User
Longtime User
After some more fiddling, if I actually use a string operation in the code:
B4X:
If Success And ExitCode = 0 Then
              
    wrk_log = wrk_log & Gen_crlf & "Adapter metric set"

Else
It works, this is beyond bizarre...

I think this is a bug so have reported it to the bug section.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…