pwittchen / prefser

Wrapper for Android SharedPreferences with object serialization and RxJava Observables
Apache License 2.0
229 stars 26 forks source link

Infinite loop when storing LinearLayout #93

Open luchfilip opened 8 years ago

luchfilip commented 8 years ago

While I know the types of data Prefser can store, I've tried to store a LinearLayout data type. The app hangs and does an infinite loop inside Gson.java on line 358:

for (TypeAdapterFactory factory : factories) {
    TypeAdapter<T> candidate = factory.create(this, type);
    if (candidate != null) {
      call.setDelegate(candidate);
      typeTokenCache.put(type, candidate);
      return candidate;
    }
  }

Also the app crashes on storing View.

Model: Nexus 5, android 6.0.1

pwittchen commented 8 years ago

Why did you want to store LinearLayout or any View?

luchfilip commented 8 years ago

I had an array of objects that I use, and in order to test a little feature I've put the view inside the object while not considering that this object is used by prefser. Then when debugging I found where exactly this loop happens.

pwittchen commented 8 years ago

The intention of prefser is storing simple data structures - not complicated objects or views. In my opinion, storing views doesn't make sense. If you want to remember a specific state of the UI, you should extract part of your code into a simpler class and then store its instance. I'm not surprised that it didn't work. It's incorrect usage of the library. You can provide StackTrace and we can eventually improve error handling or data validation, but we won't handle storing objects from Android SDK or anything like that.

luchfilip commented 8 years ago

I did not even intent to suggest that this library should store such data types; it was more about being aware this is happening and maybe you would like to handle the error in a more elegant way.

pwittchen commented 8 years ago

Can you provide StackTrace of your error? Then it will be easier to handle it.