应用程序从后台到前台时出现stackoverflow错误

时间:2016-05-18 10:34:44

标签: android retrofit2 okhttp3

有时,当我的应用程序来自后台应用程序崩溃时,其logcat如下所示,

Fatal Exception: java.lang.StackOverflowError
       at com.android.org.bouncycastle.asn1.DefiniteLengthInputStream.read(DefiniteLengthInputStream.java:74)
       at java.io.FilterInputStream.read(FilterInputStream.java:118)
       at com.android.org.bouncycastle.asn1.DefiniteLengthInputStream.read(DefiniteLengthInputStream.java:74)
       at java.io.FilterInputStream.read(FilterInputStream.java:118)
       at com.android.org.bouncycastle.asn1.DefiniteLengthInputStream.read(DefiniteLengthInputStream.java:74)
       at com.android.org.bouncycastle.util.io.Streams.readFully(Streams.java:49)
       at com.android.org.bouncycastle.util.io.Streams.readFully(Streams.java:40)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.getBuffer(ASN1InputStream.java:384)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.createPrimitiveDERObject(ASN1InputStream.java:447)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:184)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildEncodableVector(ASN1InputStream.java:193)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildDEREncodableVector(ASN1InputStream.java:204)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:173)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildEncodableVector(ASN1InputStream.java:193)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildDEREncodableVector(ASN1InputStream.java:204)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:173)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildEncodableVector(ASN1InputStream.java:193)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildDEREncodableVector(ASN1InputStream.java:204)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:173)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildEncodableVector(ASN1InputStream.java:193)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildDEREncodableVector(ASN1InputStream.java:204)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:173)
       at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272)
       at com.android.org.bouncycastle.jce.provider.CertPathValidatorUtilities.getObject(CertPathValidatorUtilities.java:339)
       at com.android.org.bouncycastle.jce.provider.CertPathValidatorUtilities.getExtensionValue(CertPathValidatorUtilities.java:325)
       at com.android.org.bouncycastle.jce.provider.RFC3280CertPathUtilities.processCertD(RFC3280CertPathUtilities.java:1268)
       at com.android.org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:310)
       at com.sec.android.security.pkix.SecCertPathValidatorSpi.engineValidate(SecCertPathValidatorSpi.java:100)
       at java.security.cert.CertPathValidator.validate(CertPathValidator.java:190)
       at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:295)
       at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:202)
       at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:612)
       at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(NativeCrypto.java)
       at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:406)
       at okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:195)
       at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:148)
       at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
       at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:188)
       at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:127)
       at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
       at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:289)
       at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:241)
       at okhttp3.RealCall.getResponse(RealCall.java:240)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
       at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
       at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
       at okhttp3.RealCall.access$100(RealCall.java:30)
       at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
       at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:841)

我正在使用改装2和杰克逊,这次崩溃发生在三星。

我的片段代码如下,

package cl.tp.ui.fragments;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cl.tp.ui.iBAPView.Empty_EndlessRecyclerView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class EngagementsOffers extends 
Fragment implements     ProcessedResult
{
int skip = 0;
private Context context;
private Engagment_offers engagementAdapter;
private List<MJob> engagementJob;

//This is my custom Recyclerview which detects onScroll when end to bottom of page or crossed the threshold.
private Empty_EndlessRecyclerView mRecyclerView;
private String accessToken = null;

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    this.context=context;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.recycler_empty_view, container, false);

    initialize(view);
    return view;
}

private void initialize(View view)
{
    accessToken = GeneralFunctions.getStorageManager(context).getValue(Constants.Other.SHAREPREFECE_APPTOKEN.toString(), null);
    mRecyclerView = (Empty_EndlessRecyclerView) view.findViewById(R.id.common_recyclerView);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mRecyclerView.getContext());
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(linearLayoutManager);

    View emptyView = view.findViewById(R.id.ev_emptyView);
    TextView textView = (TextView) emptyView.findViewById(R.id.ev_text);

    MUdetails.Data profileDetail=((ApplicationClass)context.getApplicationContext()).getProfileDetail();
    if(profileDetail!=null)
        if(profileDetail.getIsLookingForJob())
            textView.setText(getString(R.string.recycler_empty_engagementoffers));
        else
            textView.setText(getString(R.string.recycler_empty_engagementoffers_off));

    mRecyclerView.setEmptyView(emptyView);
    mRecyclerView.setProgressView(R.layout.progress_footer);

    engagementJob = new ArrayList<>();
    engagementAdapter = new Engagment_offers(engagementJob,this);
    mRecyclerView.setAdapter(engagementAdapter);
    mRecyclerView.setPager(this);

    mRecyclerView.setRefreshing(true);
    processedResult(null, Constants.Other.LOAD_MORE_METHOD);
}

private void getAllCurrentJobs() {
   /* if (totalSize == skip) {
        mRecyclerView.setRefreshing(false);
        GeneralFunctions.showToast(context.getResources().getString(R.string.toast_no_more_item), context);
        return;
    }*/
    // LogUtil.e("ss:-",mRecyclerView.isRefreshing()+"");
    RetrofitAdapters.createRetrofitService(Api.class).getMyjobOffers(accessToken,10,skip).enqueue(new Callback<MEngagementOffers>() {
        @Override
        public void onResponse(Call<MEngagementOffers> call, Response<MEngagementOffers> response) {
            mRecyclerView.setRefreshing(false);
            GeneralFunctions.parseResponse( response,Constants.CallbackConstants.JOBOFFERS,EngagementsOffers.this);
        }

        @Override
        public void onFailure(Call<MEngagementOffers> call, Throwable t) {
            GeneralFunctions.parserRetrofitError(context, t);
            mRecyclerView.setRefreshing(false);
        }
    });
}


//Custom callback for result parse from retrofit 2
@Override
public <IResponse, IMethod> void processedResult(IResponse iResponse, IMethod iMethod) {
    switch (iMethod.toString()) {
        case Constants.Other.LOAD_MORE_METHOD:
            getAllCurrentJobs();
            break;
        case Constants.CallbackConstants.JOBOFFERS:
        {
            MEngagementOffers mEngagements=((Response<MEngagementOffers>)iResponse).body();
            int size = mEngagements.getData().getNewJobOffers().size();
            skip += size;
            if (size > 0) {
                int prevousSize = engagementJob.size();
                engagementJob.addAll(mEngagements.getData().getNewJobOffers());
                engagementAdapter.notifyItemRangeInserted(prevousSize, size);
            }
        }break;
    }
}

}

1 个答案:

答案 0 :(得分:1)

我最近碰到了一些非常相似的东西。事实证明,当我想添加一个会覆盖原始版本时,我会继续添加拦截器。最终我会得到一个StackOverflowError,就像你上面发布的堆栈跟踪一样。以下讨论帮助我弄清楚发生了什么:https://github.com/square/okhttp/issues/2300