Android Question Cant debug this issue?

Scantech

Well-Known Member
Licensed User
Longtime User

i can't even track where its coming from?

Happened after failed to allocate error. Corrected that error. Cleared data and its not crashing anymore.

Can the HttpUtils2Service library get a patch to prevent this? I want to put try and catch but could not pinpoint the error loccation.
 
Last edited:

drgottjr

Expert
Licensed User
Longtime User
the error is coming from here:
Dim out As OutputStream = File.OpenOutput(TempFolder, TaskId, False)
in httputils2service.bas (part of okhttputils2). it is designed to throw a file not found exception (which it does).

what does this app do? are you downloading lots of files with it. can you show the code snippet
relating to the downloading? that file name "666" does not sound right if you are calling job.release in a timely manner,
and then not doing something you shouldn't do afterwards.

just so you know, since okhttputils2 is a b4xlib, you could add your own try/catch block at the
point referenced above. better than a crash, imho. and i think there is a clean way to exit the catch,
but causing the error in the first place would be difficult; the library is designed not to fail that way,
and many, many thousands of happy users can attest to that.

i think there may be a problem with the way you're using the lib, and while try/catch is good defensive
programming, it might be useful to see how you managed to get the crash to occur. please post your code,
if possible. also in the just-so-you-know department, the cache folder is deleted by the os in the event of
memory problems. if that folder were deleted and the library tries to access a file in it, there will be a crash.
this is what leads me to believe there was a problem relating to how the lib was used. file 666 smells.
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
its an iptv app. I was loading a m3u file with 200,000 records and writing some m3u files in subfolders (around 90 files) using arrays of string builders. I experienced memory error failed to allocate then the issue started in pclv. I fixed memory error issue with clearing the String Builder after each of writing. I was upset with the playlist and called it 666 which assigns folders in file.cache and file.dirinternal as /666. File.cache has all the images in there.

It happened frequently when scrolling with pclv. But not anymore after i did a clear data in android settings

i even added try catch in the whole code block and did not catch anything?

B4X:
Private Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    '3 for x in 4 image
    '1 for x in 2 image
    'CellSMMListView for 4 image
    'CellSMMListView3 for 2 image

    For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
 
        Dim item As CLVItem = CustomListView1.GetRawListItem(i)
        
        pnlCLV = xui.CreatePanel("")
            
        item.Panel.AddView(pnlCLV, 0, 0, item.Panel.Width, item.Panel.Height)
            
        Dim dataIndex As Int = item.Value
 
        'Create the item layout
        pnlCLV.LoadLayout(Starter.useCellName)
 
        For x = 0 To Starter.uselvForx
    
            If (dataIndex + x) <= Starter.MyM3UFileParsed.IconLink.Size Then 'Important cause there might be extra empty fields
        
                Dim WhatListIndex As Int
                WhatListIndex = (dataIndex + x) - 1
        
                Dim GetChannelName As String
                GetChannelName = StateManager.GetChannelNamewithFilters(WhatListIndex)
                        
                pnlCLV.GetView(x).GetView(1).Text = GetChannelName
                pnlCLV.GetView(x).GetView(1).Tag = WhatListIndex
 
                Dim GetIconLink As String
                GetIconLink = Starter.MyM3UFileParsed.IconLink.Get(WhatListIndex)
                            
                Dim WhatFileName As String
                WhatFileName = StateManager.GetIconFileNameByIconLinkName(GetIconLink)
                                    
                If File.Exists(File.DirInternalCache, Starter.SelectedFolder & WhatFileName) Then
                    If StateManager.blnLogOn = True Then Log(WhatFileName)
            
 
                    Try
                        pnlCLV.GetView(x).GetView(0).SetBitmap(xui.LoadBitmapResize(File.DirInternalCache, Starter.SelectedFolder & WhatFileName, pnlCLV.GetView(x).GetView(0).Width, pnlCLV.GetView(x).GetView(0).Height, True))
                        If StateManager.smViewName = 0 Then
                            If Starter.WhatTabIsIt = 2 Or Starter.WhatTabIsIt = 3 Then
                                pnlCLV.GetView(x).GetView(1).Visible = False    'title label
                            End If
                        End If
                    Catch
                        Log("CLV: " & LastException)
                    End Try
            
                Else
            
                    If GetIconLink <> "Not Available" Then
                        If StateManager.blnLogOn = True Then Log("ICon link available requesting...")
                
                        'Request URL to fill icon image
                        RequestIconLink(GetIconLink, pnlCLV.GetView(x).GetView(0), pnlCLV.GetView(x).GetView(1))
                    Else
'                        If StateManager.blnLogOn = True Then Log("IconlInk Not available")
                        'Add no image
                        pnlCLV.GetView(x).GetView(0).SetBitmap(xui.LoadBitmapResize(File.DirAssets, "No Image.png", pnlCLV.GetView(x).GetView(0).Width/2, pnlCLV.GetView(x).GetView(0).Height/2, True))

                        If StateManager.smViewName = 0 Then
                            If Starter.WhatTabIsIt = 2 Or Starter.WhatTabIsIt = 3 Then
                                pnlCLV.GetView(x).GetView(1).Visible = True    'title label
                            End If
                        End If
                    End If
            
                End If
        
            End If
    
        Next
 
    Next
 

End Sub
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Sub RequestIconLink(GetIconLink As String, PanelImage As B4XView, TitleLabel As B4XView)
    

    Dim job As HttpJob
    job.Initialize("Job2", Me)
    
    job.Tag = StateManager.GetIconFileNameByIconLinkName(GetIconLink)

    Dim poststr As String = GetIconLink
    If StateManager.blnLogOn = True Then Log("Request Icon Url: " & poststr)
    If StateManager.blnLogOn = True Then Log(" ")
    
    job.Download(poststr)
    job.GetRequest.Timeout = Starter.intIconTimeoutValue    '5 seconds default
'    job.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")
    job.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36")

    
    'Wait for download complete
    Wait For (job) JobDone(job As HttpJob)
    
    If StateManager.blnLogOn = True Then Log("JobName = " & job.JobName & ", Success = " & job.Success)
    If StateManager.blnLogOn = True Then Log("JobTag = " & job.Tag)
    
    If (job.Success = True) Then
        
        Dim WhatFilename As String
        WhatFilename = job.Tag
        
        If StateManager.blnLogOn = True Then Log(WhatFilename)
        If StateManager.blnLogOn = True Then Log(" ")

'            save icon to a file (when file is available in customlistview visiblerange it will load it instead of url request)   
        Try
            If File.IsDirectory(File.DirInternalCache, Starter.SelectedFolder) = False Then
                File.MakeDir(File.DirInternalCache, Starter.SelectedFolder)
            End If
            
            'some icon did not display. i think adding user-agent solved it?
            Dim out As OutputStream = File.OpenOutput(File.DirInternalCache, Starter.SelectedFolder & WhatFilename, False)
            File.Copy2(job.GetInputStream, out)
            out.Close

            'Display bitmap to panelimage
            PanelImage.SetBitmap(job.GetBitmap.Resize(PanelImage.Width, PanelImage.Height, True))
            If StateManager.smViewName = 0 Then
                If Starter.WhatTabIsIt = 2 Or Starter.WhatTabIsIt = 3 Then
                    TitleLabel.Visible = False    'title label
                End If
            End If
        Catch
            PanelImage.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "No Image.png", PanelImage.Width/2, PanelImage.Height/2, True))

            If StateManager.smViewName = 0 Then
                If Starter.WhatTabIsIt = 2 Or Starter.WhatTabIsIt = 3 Then
                    TitleLabel.Visible = True    'title label
                End If
            End If
            If StateManager.blnLogOn = True Then Log("Error Outputstream:" & LastException)
        End Try
                                                            
    Else
        PanelImage.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "No Image.png", PanelImage.Width/2, PanelImage.Height/2, True))

        If StateManager.smViewName = 0 Then
            If Starter.WhatTabIsIt = 2 Or Starter.WhatTabIsIt = 3 Then
                TitleLabel.Visible = True    'title label
            End If
        End If
        If StateManager.blnLogOn = True Then Log("False JobDone: ")
        If StateManager.blnLogOn = True Then Log(" ")
    End If
            
    job.Release


End Sub
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
file not found + EISDIR would point to the cache's having been emptied. the EISDIR exception occurs when you try to open a folder as if it were a file. i only glanced at your code; i was interested in the httpjob-related code, but it's not important since i see now that you are populating the cache folder yourself. okhttputils2 also populates it, so issues caused by you would make okhttputils2 fail. this is not to say that there shouldn't be some try/catch mechanism in place to avoid the crash, but the try/catch block would need to be in okhttputils2. the crash occurs there. whether the problem would eventually occur in your code is moot; it occurred elsewhere first.

i see you have just posted okhttp-related code. i think we're on a different level now. you may want to try using dirinternal or safedirexternal and let okhttputils2 manage the cache folder by itself. other than knowing that the cache folder is automatically removed when necessary, i don't know if the same amount of memory is allocated to both cache and dirinternal. but it's clear to me that your filling the cache folder caused okhttputils2 to crash. try/catch at a certain spot in that lib is not a bad suggestion, but changing the folder you use for your files is an easier fix (i would say)
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
httputils2service_hc_responsesuccess (java line: 128)
java.io.FileNotFoundException: /data/user/0/whoopersx.iptv/cache/777: open failed: EISDIR (Is a directory)
    at libcore.io.IoBridge.open(IoBridge.java:574)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:259)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
    at whoopersx.iptv.httputils2service._hc_responsesuccess(httputils2service.java:128)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.BA$2.run(BA.java:395)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:230)
    at android.os.Looper.loop(Looper.java:319)
    at android.app.ActivityThread.main(ActivityThread.java:8919)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Caused by: android.system.ErrnoException: open failed: EISDIR (Is a directory)
    at libcore.io.Linux.open(Native Method)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8782)
    at libcore.io.IoBridge.open(IoBridge.java:560)
    ... 14 more
Error in release mode.

I put empty folder name 777 in file.internalcache and the error occurs again. I don't even call that folder 777, i use a different playlist folder name. I checked all filenames have strings. something is strange indeed.

No empty folder in file.internalcache = ok. My temp workaround is on app startup delete empty folder. Lol

What a headache some. Thanks for your help. i may need to dig deeper.
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
    Dim job As HttpJob = TaskIdToJob.Get(TaskId)
    If job = Null Then
        Log("HttpUtils2Service (hc_ResponseSuccess): job completed multiple times - " & TaskId)
        Return
    End If
    job.Response = Response
    Dim out As OutputStream = File.OpenOutput(TempFolder, TaskId, False)
    #if HU2_PUBLIC
    job.Out = out
    #end if
    Response.GetAsynchronously("response", out , _
        True, TaskId)
End Sub

#8 line is the culprit. Just as you said.
I removed the library and copied its class to my app. I'm adding try and catch.

i logged
TempFolder = /data/user/0/whoopersx.iptv/cache
j.Tag = mx90alip.png
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
adding the try is the easy part; plotting the exit from the catch could be problematic. notice lines #5 and #12. will a simple return work? or do you have to call getasynchronously with success = false? then there's the matter of setting things up to trigger an exception which will test your try/catch block
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User

B4X:
Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
    Try
        Dim job As HttpJob = TaskIdToJob.Get(TaskId)
        If job = Null Then
            Log("HttpUtils2Service (hc_ResponseSuccess): job completed multiple times - " & TaskId)
            Return
        End If
        job.Response = Response
        Dim out As OutputStream = File.OpenOutput(TempFolder, TaskId, False)
        #if HU2_PUBLIC
        job.Out = out
        #end if
        Response.GetAsynchronously("response", out , _
            True, TaskId)
 
        Log("TaskId" & TaskId)
        Log("TAG: " & job.Tag)
        Log(" ")
    Catch
        Log("I found error here: " & TempFolder)
        Log("TaskId" & TaskId)
        Log("TAG: " & job.Tag)
        Log(" ")
    End Try
End Sub
Its using TaskId as integer to assign the files. There is no extension. See the pattern above. Any numbers folder name will pose an issue in cache using this library

Erel is one of the best top programmer. programming mistake?

will a simple return work? or do you have to call getasynchronously with success = false?
im not sure about this.
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Here is a demo of the crash. Anybody using folder number names in file.internalCache and using download with OKHttpUtils2 library will have an issue as provided below.
 

Attachments

  • OKHttpUtils2 Example crash.zip
    10.3 KB · Views: 47
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…