Skip to content

Commit

Permalink
Jersey Microprofile RestClient - NullPointerException when a optional…
Browse files Browse the repository at this point in the history
… FormParam is null eclipse-ee4j#5254

Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
  • Loading branch information
jbescos authored and senivam committed Feb 16, 2023
1 parent 149650d commit a542fa9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -45,7 +45,7 @@ Form handleParameter(Form form, Class<? extends Annotation> annotationClass, Obj
form.param(formParamName, v.toString());
}
} else {
form.param(formParamName, resolvedValue.toString());
form.param(formParamName, resolvedValue == null ? null : resolvedValue.toString());
}
return form;
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -21,6 +21,7 @@

import javax.json.JsonValue;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
Expand Down Expand Up @@ -76,4 +77,10 @@ default String sayHi() {
@Path("content1/{content1}/content0/{content0: [0-9]{4}}")
@Produces(MediaType.TEXT_PLAIN)
String regex0(@PathParam("content1") String context0, @PathParam("content0") String context1);

@POST
@Path("formParam")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
String formParam(@FormParam("param") String param);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -71,4 +71,9 @@ public String regex(String content) {
public String regex0(String context0, String context1) {
return context0 + "_" + context1;
}

@Override
public String formParam(String param) {
return param;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -56,4 +56,12 @@ public void testGetIt() throws URISyntaxException {

assertEquals("Hi", app.sayHi());
}

@Test
public void testFormParam() throws URISyntaxException {
String response = RestClientBuilder.newBuilder()
.baseUri(new URI("http://localhost:9998"))
.build(ApplicationResource.class).formParam(null);
assertEquals("", response);
}
}

0 comments on commit a542fa9

Please sign in to comment.