Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Peek throw com.google.gson.JsonSyntaxException #82

Open
thedamfr opened this issue Jul 20, 2015 · 5 comments
Open

Peek throw com.google.gson.JsonSyntaxException #82

thedamfr opened this issue Jul 20, 2015 · 5 comments

Comments

@thedamfr
Copy link

Hey !

Sometimes, in production, I will get something wrong and an object will be stuck. The Queue is going to throw a com.google.gson.JsonSyntaxException each time this object is peek()

Do you have any idea why ?

For now, all I can do is ask the user to clear data cache, but some datas are lost each time.

Thanks !

@thedamfr
Copy link
Author

Defensive code here ! Not sexy

But here is a sneak peak of how to get defensive about this :

 } catch (JsonSyntaxException jsonSyntaxException) {
            // Crap
            try {
                // Use refexivity to get the unparsable string
                Field delegateField = InventoryTaskQueue.class.getDeclaredField("delegate");
                delegateField.setAccessible(true);
                FileObjectQueue delegateValue = (FileObjectQueue) delegateField.get(queue);
                Field queueFileField = FileObjectQueue.class.getDeclaredField("queueFile");
                queueFileField.setAccessible(true);
                QueueFile queueFileValue = (QueueFile) delegateField.get(delegateValue);
                byte[] bytes = queueFileValue.peek();

                // Put that shit in Crashlytics
                Crashlytics.setString("Problematic JSON", new String(bytes));

                // Also Reflexivity is a very dangerous way of life. Catch them all
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
                Crashlytics.logException(e);
            } catch (IOException e) {
                e.printStackTrace();
                Crashlytics.logException(e);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                Crashlytics.logException(e);
            }
            // Log exception to Crashlytics
            Crashlytics.logException(jsonSyntaxException);

            // Remove that stuck shit
            queue.remove();

        }

@thedamfr
Copy link
Author

Okay. Real life aka. Production shows that queue.remove() send a NoSuchElement exception in that case.

@sergiopantoja
Copy link

@thedamfr Ah! I'm glad I'm not alone on this one. I encounter the same exact errors in production: I've seen the queue get stuck several times, and I've also seen the NoSuchElement exception on queue.remove().

I was able to debug the queue one time when it was stuck. queue.peek() was returning NULL, but queue.size() was > 0. Didn't have enough time to dig deeper unfortunately.

@ragunathjawahar
Copy link

+1, happens with protocol buffers as well while peeking.

java.net.ProtocolException: Unexpected tag 0

@JakeWharton
Copy link
Collaborator

Are you peeking on a different thread than writing?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants