Invalid Malformed URL
Author: nathancassanoCreated Apr 15, 2019Updated Aug 16, 2026
LabelsBug
The path of a URL contains a colon symbol which is causing the call to fail.
Using version com.squareup.retrofit2:retrofit:2.5.0
Code:
public interface ClientApi {
@PUT("user:email={email}/login")
Call<ResponseBody> login(@Path("email") String email, @Body String pass);
@PUT("./user:email={email}/login")
Call<ResponseBody> loginRelative(@Path("email") String email, @Body String pass);
...Regular path Stack trace:
Caused by: java.lang.IllegalArgumentException: Malformed URL. Base: https://test.com/restapi/, Relative: user:[email protected]/login
at retrofit2.RequestBuilder.get(RequestBuilder.java:221)
at retrofit2.RequestFactory.create(RequestFactory.java:111)
at retrofit2.OkHttpCall.createRawCall(OkHttpCall.java:190)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:173)
at Service.login(Service.java:38)Think the code needs to treat the relative portion of the URL like an absolute URL when parsing.
Relative path
Using a retaliative path annotation ./ does not solve this issue.
Stack trace:
Caused by: java.lang.IllegalArgumentException: @Path parameters shouldn't perform path traversal ('.' or '..'):
at retrofit2.RequestBuilder.addPathParam(RequestBuilder.java:113)
at retrofit2.ParameterHandler$Path.apply(ParameterHandler.java:99)
at retrofit2.RequestFactory.create(RequestFactory.java:108)
at retrofit2.OkHttpCall.createRawCall(OkHttpCall.java:190)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:173)Bug report unit test https://gist.github.com/nathancassano/f675e2fd1c64d4b6002afea37bf5fee4
Source: lysine-dev/retrofit