[Bug]: REST transport: getTask builds an invalid URL for single-digit historyLength
Les mainteneurs répondent en général sous 2 jours
@014-code y travaille déjà.
Depuis le 2/10/2026.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 88/100
Piste de recherche
Commencez dans client/transport/rest/src/main/java/io/a2aproject/a2a/client/transport/rest/RestTransport.java, au niveau de getTask, et examinez le formatage de l’URL. Exécutez RestTransportTest.testGetTask avec un historyLength à un seul chiffre, tel que 5, puis ajoutez une couverture de régression montrant que l’URI générée est valide et que la requête ne contient aucun remplissage ; normalisez les chaînes de format associées si elles sont incluses dans la modification.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
What happened?
Summary
RestTransport.getTask builds the request URL with a String.format pattern that uses width specifiers (%2d) where argument-index specifiers (%2$d) were intended. For a single-digit historyLength (0–9), %2d left-pads the value with a space, producing historyLength= 5. A raw space is illegal in a URI, so java.net.URI.create(...) throws IllegalArgumentException: Illegal character in query, and the getTask call fails before any request is sent.
Affected code
client/transport/rest/src/main/java/io/a2a/client/transport/rest/RestTransport.java, in getTask:
url.append(String.format("/tasks/%1s?historyLength=%2d", taskQueryParams.id(), taskQueryParams.historyLength()));
In Java format syntax, an argument index requires a trailing $ (%2$d). Without it, %2d means "decimal, minimum width 2", and %1s means "string, minimum width 1" — these are width fields, not argument references. The %1s on the id is harmless only by accident (a UUID is always wider than 1, so nothing is padded); the %2d on the integer pads any single-digit value.
Reproduction
String.format("/tasks/%1s?historyLength=%2d", "de38c76d-d54c-436c-8b9f-4c2703648d64", 5);
// => "/tasks/de38c76d-d54c-436c-8b9f-4c2703648d64?historyLength= 5"
// ^ stray space
URI.create("https://host/tasks/de38c76d-d54c-436c-8b9f-4c2703648d64?historyLength= 5");
// => java.lang.IllegalArgumentException: Illegal character in query at index N: ...historyLength= 5
Behavior by value:
| historyLength | formatted query | valid URI? |
|---|---|---|
| 1–9 | historyLength= N (leading space) |
❌ |
| 0 | n/a — getTask skips the query when historyLength <= 0 |
✅ |
| ≥ 10 | historyLength=NN |
✅ |
So any getTask call with historyLength in 1–9 fails. This is the common case (clients typically request a small history window), which makes the practical impact high.
Why existing tests don't catch it
RestTransportTest.testGetTask uses new TaskQueryParams("...", 10) — a two-digit value that satisfies the width-2 field, so no space is injected and the URL stays valid. Single-digit values are never exercised.
Suggested fix
Drop the width (preferred) or use real positional indices:
// simplest
url.append(String.format("/tasks/%s?historyLength=%d", taskQueryParams.id(), taskQueryParams.historyLength()));
// or, if explicit indices are desired
url.append(String.format("/tasks/%1$s?historyLength=%2$d", taskQueryParams.id(), taskQueryParams.historyLength()));
Also recommend adding a regression test that calls getTask with a single-digit historyLength (e.g. 5) and asserts the resulting URL/query is well-formed.
Related occurrences (same specifier mistake, latent)
The same %Ns width-vs-index pattern appears on other URL-building sites in RestTransport.java (e.g. /tasks/%1s:cancel, /tasks/%1s/pushNotificationConfigs/%2s, /tasks/%1s:subscribe). These don't currently misbehave because their arguments are strings whose length exceeds the width, so no padding occurs — but they're the same bug waiting on a short/empty value and would be worth normalizing to %s in the same change.
Environment
- Observed on the v1.x line (
org.a2aproject.sdk) and the v0.3 line (io.github.a2asdk:0.3.3.Final); both contain the identicalhistoryLength=%2dline, and it is still present on the latestmain. - Transport: HTTP+JSON (REST). JSON-RPC transport is unaffected (it doesn't build this query).
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
- Langage dominant
- Java
- Étoiles
- 507
- Forks
- 192
- Merge moyen
- 3 j 8 h
- PR mergées (30 j)
- 23
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de a2aproject/a2a-java
-
fix: handle blank push notification config id consistently across transportsPeut-être pris @prachisinghal-1 l’a pris il y a 6 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
a2aproject/a2a-java#1012 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
a2aproject/a2a-java#464 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
Create a sample that demonstrates how to use a shared contextId across multiple tasksPeut-être à nouveau libre @tanish111 l’a pris il y a 373 jours, et aucune pull request n’est ouverte. Ouvertesample
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
a2aproject/a2a-java#375 · 5 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 2 jours
-
Task state transitions are not trackedPeut-être à nouveau libre @sumitvairagar l’a pris il y a 12 jours, et aucune pull request n’est ouverte. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
a2aproject/a2a-java#1222 · 4 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
No structured payload loggingPeut-être pris @katepallewarprathmesh-sketch l’a pris il y a 10 jours. Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 18/100
a2aproject/a2a-java#1221 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de a2aproject/a2a-java
Issues similaires
-
Update samples to Citrus 5.1.0Peut-être pris @asuruceanu l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
snowflakedb/snowflake-kafka-connector#1610 ·
Les mainteneurs répondent en général sous 1 jour
-
add multipart/form-data exampleOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
swagger-api/swagger-petstore#245 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
liquid-java/liquidjava#443 ·
Les mainteneurs répondent en général sous 2 jours