Android Question Crash at okhttp3.Headers$Builder.checkNameAndValue

roumei

Active Member
Licensed User
I'm using the AWS_S3 signature calculator by JackKirk: https://www.b4x.com/android/forum/t...re-calculator-b4x-works-on-b4a-b4i-b4j.81272/ and OkHttpUtils2 (2.92) to download files from an AWS S3 bucket in my published app (https://play.google.com/store/apps/details?id=com.planlauf.derlousberg). Everything is working without a problem for weeks now but a couple of days ago I had more than 20 crashes on two devices running Android 8 and 10 on a single day (but none since). Google Play Console reports an IllegalArgumentException at okhttp3.Headers$Builder.checkNameAndValue.

Has anyone experienced something like this? Could it be a AWS S3 problem instead of a bug?

Thank you!

Google Play Console Crash Report:
java.lang.IllegalArgumentException:
  at okhttp3.Headers$Builder.checkNameAndValue (Headers.java:320)
  at okhttp3.Headers$Builder.add (Headers.java:270)
  at okhttp3.Request$Builder.addHeader (Request.java:176)
  at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest.SetHeader (OkHttpClientWrapper.java:470)
  at com.planlauf.derlousberg.main$ResumableSub_AWSDownloadFile.resume (main.java:1852)
  at com.planlauf.derlousberg.main._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv7 (main.java:1641)
  at com.planlauf.derlousberg.main$ResumableSub_ShowDownloadDialog.resume (main.java:11336)
  at com.planlauf.derlousberg.main._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv6 (main.java:11266)
  at com.planlauf.derlousberg.main._btnstartordownload_click (main.java:2340)
  at java.lang.reflect.Method.invoke (Native Method)
  at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:213)
  at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:197)
  at anywheresoftware.b4a.BA.raiseEvent (BA.java:193)
  at anywheresoftware.b4a.objects.ViewWrapper$1.onClick (ViewWrapper.java:80)
  at android.view.View.performClick (View.java:7869)
  at android.widget.TextView.performClick (TextView.java:14958)
  at android.view.View.performClickInternal (View.java:7838)
  at android.view.View.access$3600 (View.java:886)
  at android.view.View$PerformClick.run (View.java:29362)
  at android.os.Handler.handleCallback (Handler.java:883)
  at android.os.Handler.dispatchMessage (Handler.java:100)
  at android.os.Looper.loop (Looper.java:237)
  at android.app.ActivityThread.main (ActivityThread.java:8019)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1100)

Download code:
Private Sub AWSDownloadFile(AWSFolder As String, AWSFilename As String, sOutputDir As String) As ResumableSub
    
    Dim dBackupTimeZone As Double = DateTime.TimeZoneOffset
    DateTime.SetTimeZone(0)
    
    If File.Exists(sOutputDir, AWSFilename) = True Then
        Try
            File.Delete(sOutputDir, AWSFilename)
        Catch
            Log(LastException)
        End Try
    End If
    
    If AWSFolder <> "" Then
        If AWSFolder.CharAt(AWSFolder.Length-1) <> "/" Then AWSFolder = AWSFolder & "/"
    End If

    AWS_S3.AWS_Access_Key_ID = AWSAccessKeyID
    AWS_S3.AWS_Secret_Access_Key = AWSSecretAccessKey
    AWS_S3.AWS_Region = "eu-central-1"
    AWS_S3.AWS_End_Point = AWSEndPoint
    AWS_S3.AWS_S3_Bucket_Name =  AWSBucketName
    AWS_S3.AWS_S3_File_Name = AWSFolder & AWSFilename
    AWS_S3.AWS_S3_HttpMethod = "GET"
    AWS_S3.AWS_S3_Query_map.Initialize
    AWS_S3.AWS_S3_Query_map.Clear
    Private null_bytes() As Byte
    AWS_S3.AWS_S3_Payload = null_bytes
    AWS_S3.AWS_S3_GMT_DateTime = DateTime.Now
    AWS_S3.AWS_S3_OtherHeader_map.Initialize
    AWS_S3.AWS_S3_OtherHeader_map.Clear
    Dim AWS_job As HttpJob
    
    AWS_job.Initialize("AWS_job", Me)
    AWS_job.Download(AWS_S3.URI)
    Private wk_hdr_map As Map
        
    wk_hdr_map.Initialize
    wk_hdr_map = AWS_S3.FullHeaderMap
    
    For Each a As String In wk_hdr_map.Keys
        If a <> "host" Then
            AWS_job.GetRequest.SetHeader(a, wk_hdr_map.Get(a))
        End If
    Next
    
    AWS_job.GetRequest.SetHeader("Authorization", AWS_S3.Authorization)

    ' Wait for download to finish
    Wait For (AWS_job) JobDone(AWS_job As HttpJob)
    
    ' Copy file
    If AWS_job.Success = True Then
        Private wrk_in As InputStream
        wrk_in = AWS_job.GetInputStream
        Private wrk_out As OutputStream
        wrk_out = File.OpenOutput(sOutputDir, AWSFilename, False)
        File.Copy2(wrk_in, wrk_out)
        wrk_in.Close
        wrk_out.Close
    End If
      
    AWS_job.Release
    DateTime.SetTimeZone(dBackupTimeZone)
    
    Return File.exists(sOutputDir, AWSFilename)
        
End Sub
 
Top