android Volley library NegativeArraySizeException

2019-05-11 01:53发布

问题:

I'm getting this NegativeArraySizeException from Volley library. This error started after I changed Volley android-library-module to a maven dependencies like compile 'com.android.volley:volley:1.0.0'

I've this singleton pattern and I change the addToRequestQueue method to avoid double request bug with following link:

public <T> void addToRequestQueue(Request<T> req) {
        req.setRetryPolicy(new DefaultRetryPolicy(
                0,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        getRequestQueue().add(req);
    }

I see that official Android-Volley does not getting any updates. So Do I have to change it back what it was? Or is there any way to fix this bug? Thanks in advance.

Fatal Exception: java.lang.NegativeArraySizeException: -603989761
       at com.android.volley.toolbox.DiskBasedCache.streamToBytes(DiskBasedCache.java:323)
       at com.android.volley.toolbox.DiskBasedCache.readString(DiskBasedCache.java:541)
       at com.android.volley.toolbox.DiskBasedCache.readStringStringMap(DiskBasedCache.java:563)
       at com.android.volley.toolbox.DiskBasedCache$CacheHeader.readHeader(DiskBasedCache.java:404)
       at com.android.volley.toolbox.DiskBasedCache.initialize(DiskBasedCache.java:157)
       at com.android.volley.CacheDispatcher.run(CacheDispatcher.java:84)