Core: documented keep rules do not preserve reflective model construction under strict R8
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- Ein halber Tag
- Anfängerfreundlichkeit
- 40/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- java
- Bereich
- build-system, data
Rechercherichtung
Start with the standalone rules in google-http-client-assembly/proguard-google-http-client.txt and the reflective path in google-http-client/src/main/java/com/google/api/client/util/Types.java (newInstance, around lines 101-119). Run the reproducer's run.py against the documented and workaround rule sets to see the three parsing cases fail and pass. Done when the documented rules keep public no-argument constructors for model classes, those cases pass, and an R8 regression test covers reflective model construction.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
JSON parsing can fail under strict R8 full mode even when using the library’s documented ProGuard rules. I reproduced this with the latest published google-http-client and google-http-client-gson 2.2.0.
The documented rules preserve generic signatures, annotations, and @Key fields, but do not explicitly preserve model classes and their public no-argument constructors. In the reproducer, R8 makes a GenericJson response model abstract and removes its constructor. Parsing then fails when the library attempts to construct that model reflectively.
Environment
- macOS 26.5
- OpenJDK/JBR 25.0.3
google-http-clientandgoogle-http-client-gson2.2.0- Gson 2.11.0 and Guava 33.4.8-android
- R8 9.4.24, bundled with AGP 9.4.1
- R8 release mode, with
setProguardCompatibility(false)andenableLegacyFullModeForKeepRules(false)
Reproduction
The attached reproducer.zip contains synthetic model fixtures, both rule configurations, and a runner. Extract it and run:
cd reproducer
python3 run.py --r8-jar /path/to/builder-9.4.1.jar
The runner downloads the pinned parsing dependencies, compiles an unminified control, and runs R8 with the documented rules and with the workaround below. R8 processes the fixture and both Google HTTP Client JARs together. Gson and Guava are supplied as library dependencies.
The runner checks these results automatically:
| Test | Unminified | Documented rules | With workaround |
|---|---|---|---|
| Plain model with typed nested list | Pass | Fail | Pass |
GenericJson model with typed nested list |
Pass | Fail | Pass |
| Supplied root with reflected nested model | Pass | Fail | Pass |
| Parameterized request serialization | Pass | Pass | Pass |
The parsing tests assert scalar values and nested model types. The runner exits successfully only when the expected failures and successes are observed.
Representative failure
The retraced GenericJson failure includes:
Caused by: java.lang.IllegalArgumentException: unable to create new instance of class repro.a because it is abstract and because it has no accessible default constructor
at com.google.api.client.util.Types.handleExceptionForNewInstance(Types.java:162)
at com.google.api.client.util.Types.newInstance(Types.java:117)
at com.google.api.client.util.Data.newMapInstance(Data.java:550)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:766)
...
Caused by: java.lang.NoSuchMethodException: repro.a.<init>()
The mapping identifies repro.a as the fixture’s GenericRoot model. The other two parsing failures are ClassCastException failures associated with lost reflected model/type retention; they are not separate demonstrations of missing constructors.
Workaround
Keep the existing attribute and annotated-field rules, and additionally use:
-keepclasseswithmembers,allowobfuscation class * {
@com.google.api.client.util.Key <fields>;
public <init>();
}
This fixes all three parsing cases in the reproducer.
The original annotated-field rule remains necessary for models that do not match this constructor rule, including request classes with only parameterized constructors. It also preserves field names when @Key uses its default name, while the additional rule permits class-name obfuscation.
Reflective construction in 2.2.0
In 2.2.0, JSON model construction reaches Types.newInstance(), which calls Class.newInstance() and requires a public no-argument constructor.
The release’s standalone ProGuard configuration preserves attributes and annotated fields but omits constructor protection. The core JAR also does not bundle Android consumer keep rules.
Could the project update the documented rules, ship appropriate consumer rules, and add an R8 regression test for reflective model construction?
Related: #1843 reports missing documentation and a similar full-mode construction failure. PR #2171 restores the documentation using the existing rules.
For simplicity, this reproducer uses JVM classfile output. It does not test an Android APK using 2.2.0.
- Vorherrschende Sprache
- Java
- Sterne
- 1.4k
- Forks
- 476
- Ø Merge
- 10 Std. 47 Min.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus googleapis/google-http-java-client
-
Core: Validate header names and values to prevent CRLF injectionEvtl. vergeben @insaf021 hat das vor 106 Tagen übernommen. Offenpriority: p3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Core: XmlPullParser processes external DTD entities (XXE) — disable FEATURE_PROCESS_DOCDECL in Xml#createParser()Evtl. vergeben @insaf021 hat das vor 106 Tagen übernommen. Offenpriority: p3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
Core: LowLevelHttpResponse not disconnected when HttpResponse construction throws RuntimeExceptionEvtl. vergeben @insaf021 hat das vor 106 Tagen übernommen. Offenpriority: p3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
type: cleanup
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
org.apache.http.conn.ssl.SSLSocketFactory is deprecatedEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offenpriority: p2 type: cleanup
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Alle Issues in googleapis/google-http-java-client
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
finos/fluxnova-bpm-platform#387 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
-
Schwierigkeit 2/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
cpp-best-practices/project_validator#251 ·
Maintainer antworten meist innerhalb von 1 Tag
-
backend enhancement
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 70/100
damodharg6/payledger#16 ·
-
[Bug]: An initiative list with no current entry logs an error on every changeEvtl. vergeben @dwizard0 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag