Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception on serialization on Samsung Galaxy S5

Tags:

java

android

In my app I pass a data object from one Activity to another. The code is quite straightforward, on the first Activity:

    Intent intent = new Intent(getActivity(), BlablaActivity.class);
    intent.putExtra(Values.KEY_ITEM, item);

and on the receiving Activity:

    Intent intent = getActivity().getIntent();
    item = (Item) intent.getSerializableExtra(Values.KEY_ITEM);

The Advertising class is very simple too:

public class Advertising implements Serializable {

    private static final long serialVersionUID = -7292860618498106953L;

    private Content content;
    private Anchor anchor;
    private String target;
    private String id;

// ...

}

And the Anchor class which seems to be causing this problem:

public class Anchor implements Serializable {

    private static final long serialVersionUID = 7360857799761417956L;

    public String value;
    public String label;

// ...

}

I get the following exception only for the Samsung Galaxy S5 (sm-g900f):

Caused by: java.lang.IllegalArgumentException: field de.mycompany.model.Advertising.anchor
has type de.mycompany.model.resultandexpose.Anchor, got de.mycompany.model.resultandexpose.Anchor

and I can not make any sense of this, the expected class is the actual class. This seems to be yet another Samsung-specific problem. Anyone experienced this and knows a fix or has an idea what the cause for this is?

EDIT:

  1. Yes, I am using Proguard. The proguard file looks like this:

    -keepattributes ** -keep class !android.support.v7.internal.view.menu., {*;} -dontpreverify -dontoptimize -dontshrink -dontwarn **

The second line is a workaround for a known bug on Samsung devices and shouldn't touch any classes except those in the android.support.v7.internal.view.menu.* package.

  • The serialVersionUID of the Anchor class is unique across all my classes.

  • Switching to Parcelable would mean a massive overhaul of the whole project. Passing objects as Serializable should work on all devices.

  • The Anchor class is just one example of this bug which happens on several other classes that basically look the same or very similar. So it isn't that one class but seems to be a more general problem.

like image 968
fweigl Avatar asked Jun 08 '15 07:06

fweigl


People also ask

What is serialization exception?

SerializationException(String, Exception) Initializes a new instance of the SerializationException class with a specified error message and a reference to the inner exception that is the cause of this exception.

Why are exceptions serializable?

All exceptions by default are serializable and that's a language design decision because the authors wanted exceptions to be capable of being sent across the wire without any special configuration.


2 Answers

I had simillar problem to yours, and I found that with lolipop update on galaxy s5 devices samsung uses bugged multidex implementation. You can check my question here explaining the problem. Someone answered to my question but I didn't checked if it works yet. Maybe this will help you.

like image 187
rwojcik Avatar answered Oct 17 '22 04:10

rwojcik


You should look at Parcelable for passing object between two activities with intent.

You can look at this tutorial that explain how it works, I suggest also to get a look at the Android Doc.

like image 24
Mathieu Bertin Avatar answered Oct 17 '22 04:10

Mathieu Bertin