Skip to content

Commit b4ad9da

Browse files
SUPERCILEXsamtstern
authored andcommitted
Fix crash when part of the exception tree isn't serializable (#1191)
1 parent 39c85f0 commit b4ad9da

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

auth/src/main/java/com/firebase/ui/auth/IdpResponse.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
import com.google.firebase.auth.GoogleAuthProvider;
2929
import com.google.firebase.auth.TwitterAuthProvider;
3030

31+
import java.io.ByteArrayOutputStream;
32+
import java.io.IOException;
33+
import java.io.ObjectOutputStream;
34+
3135
/**
3236
* A container that encapsulates the result of authenticating with an Identity Provider.
3337
*/
@@ -195,7 +199,25 @@ public void writeToParcel(Parcel dest, int flags) {
195199
dest.writeParcelable(mUser, flags);
196200
dest.writeString(mToken);
197201
dest.writeString(mSecret);
198-
dest.writeSerializable(mException);
202+
203+
ObjectOutputStream oos = null;
204+
try {
205+
oos = new ObjectOutputStream(new ByteArrayOutputStream());
206+
oos.writeObject(mException);
207+
208+
// Success! The entire exception tree is serializable.
209+
dest.writeSerializable(mException);
210+
} catch (IOException e) {
211+
// Somewhere down the line, the exception is holding on to an object that isn't
212+
// serializable so default to some exception. It's the best we can do in this case.
213+
dest.writeSerializable(new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR));
214+
} finally {
215+
if (oos != null) {
216+
try {
217+
oos.close();
218+
} catch (IOException ignored) {}
219+
}
220+
}
199221
}
200222

201223
@Override

0 commit comments

Comments
 (0)