firebase / firebase/firebase-android-sdk

Actual types passed to generic POJO super classes and to generic collection fields are ignored

Open
#5,334 2 comments 0 reactions 0 assignees View on GitHub
api: firestore type: feature request
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

Description

### [REQUIRED] Step 2: Describe your environment

* Android Studio version: Android Studio Giraffe | 2022.3.1 Patch 1
* Firebase Component: Firestore
* Component version: 24.6.1

### [REQUIRED] Step 3: Describe the problem

Given the classes
```java
class BaseBean {
public T value;
}

class SubBean extends BaseBean {}
```
if you try to deserialize into the sub-bean, you get `java.lang.IllegalStateException: Could not resolve type T`. Same is true for a base bean with a setter that takes a T parameter.

While debugging this, I found that given the classes
```java
class MapBean {
public Map values;
}

class MapSubBean extends MapBean {}

class MapBeanHolder {
public MapBean map;
}
```
deserializing into MapSubBean or MapBeanHolder, the code errs on the lenient side, and would accept any type of values into the `values` map.

I have a proposed backward-compatible fix for both issues. Should I post a PR?

I have posted this bug and the corresponding PR on the other version of this library (https://github.com/googleapis/java-firestore/issues/1313 & https://github.com/googleapis/java-firestore/pull/1323 respectively).

Contributor guide

Open the contributing guide

Research direction

Start by reproducing deserialization with the BaseBean/SubBean and MapBean examples in the issue, then review the corresponding java-firestore issue 1313 and pull request 1323 for prior investigation. Done means generic type T resolves through the subclass and collection values are validated against the actual generic type without breaking existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.