question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serialization and de-serialization of certain objects does not work as expected

See original GitHub issue

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

  • For general technical questions, post a question on StackOverflow with the firebase tag.
  • For general Firebase discussion, use the firebase-talk google group.
  • For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: 4.1.3
  • Firebase Component: inappmessaging
  • Component version: 20.0.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

The problem java.lang.ClassNotFoundException: com.google.android.gms.org.conscrypt.OpenSSLRSAPrivateCrtKey at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:628) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1615) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1520) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1776) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2002) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1926) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1803) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)

Without SDK of Firebase InApp Messaging (FIAM), de-serialization and serialization works as expected. Adding the firebase-inappmessaging-display dependency to the project, causes this completely separate part to throw an exception.

Relevant Code:

To generate RSA:

public static KeyPair generateRSAKeyPair() {
        KeyPairGenerator keyGen = null;
        KeyPair keyPair = null;
        try {
            keyGen = KeyPairGenerator.getInstance("RSA");
            keyGen.initialize(1024);
            keyPair = keyGen.genKeyPair();
        } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
            e.printStackTrace();
        }
        return keyPair;
    }

To serialize:

public static byte[] serializeClientKeyPair(KeyPair clientKeyPair) {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        ObjectOutputStream o;
        try {
            o = new ObjectOutputStream(b);
            o.writeObject(clientKeyPair);
        } catch (IOException e) {
            e.printStackTrace();
        }
        byte[] res = b.toByteArray();
        return res;
    }

And to de-serialize:

public static KeyPair deserializeKeyPair(byte[] serializedKeyPair) {
        ByteArrayInputStream bi = new ByteArrayInputStream(serializedKeyPair);
        ObjectInputStream oi;
        Object obj = null;
        try {
            oi = new ObjectInputStream(bi);
            obj = oi.readObject();
        } catch (StreamCorruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return ((KeyPair) obj);
    }

When including FIAM SDK to the project, with an Android >=9, exception is thrown at obj = oi.readObject(); when doing the steps:

                KeyPair keyPair = generateRSAKeyPair();
                byte[] serialized = serializeClientKeyPair(keyPair);
                KeyPair deserializedKeyPair = deserializeKeyPair(serialized);

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eldhosembabucommented, Aug 3, 2021

hi @MarceloMaia2 ,

thanks for providing the sample app and it helps!

I was able to reproduce the issue and we are looking into it. Will keep you posted.

Let me know if you are experiencing this issue related with any other firebase SDKs other than FIAM SDK

1reaction
eldhosembabucommented, May 24, 2021

Could you please provide a sample project with detailed steps to reproduce this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

I am serializing an object in Java but upon deserialization, its ...
I am serializing an object in Java but upon deserialization, its state is not as expected. How can I retain the object's state?...
Read more >
Serialization and Deserialization Issues in Spring REST
This way you can return errors occurring at the deserialization level to Spring Boot, which expects a deserialized object but gets a String ......
Read more >
Deserialization error: Expected to find json object at path '' #31
The type I try to deserialize from that is Media[] or List<Media> (tried both). JsonSerializationException.SpecificationInformation is null ...
Read more >
Serialization and Deserialization - WCF - Microsoft Learn
A serializer created for a certain root type cannot be used to serialize (or deserialize ) another type, unless the type is derived...
Read more >
Serialization Validation in Java - Baeldung
Serialization is the process of converting the state of an object into a byte stream. Serialized objects are primarily used in Hibernate, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found