prefser icon indicating copy to clipboard operation
prefser copied to clipboard

Infinite loop when storing LinearLayout

Open luchfilip opened this issue 9 years ago • 5 comments

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

luchfilip avatar May 13 '16 23:05 luchfilip

Why did you want to store LinearLayout or any View?

pwittchen avatar May 13 '16 23:05 pwittchen

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.

luchfilip avatar May 13 '16 23:05 luchfilip

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.

pwittchen avatar May 13 '16 23:05 pwittchen

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.

luchfilip avatar May 13 '16 23:05 luchfilip

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

pwittchen avatar May 13 '16 23:05 pwittchen