Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty query parameter leads to collection of null #3435

Open
dsvensson opened this issue Aug 27, 2020 · 1 comment
Open

Empty query parameter leads to collection of null #3435

dsvensson opened this issue Aug 27, 2020 · 1 comment

Comments

@dsvensson
Copy link

Consider the following endpoint:

	@GET
	fun listStuff(@QueryParam("id") ids: Set<UUID>): List<Stuff> {
		...
	}

When issuing curl http://localhost/liststuff?id= .. that is, id without a value. The Set<UUID> ids will be a set that contains one null item.

I've tried adding @NotEmpty Set<UUID>, and Set<@NotNull UUID> and various permutations, without getting the endpoint to reject the request.

Is this a known limitation or am I missing something?

@joschi
Copy link
Member

joschi commented Aug 27, 2020

@dsvensson Thanks for reporting this!

What you describe is the default behavior of Jersey 2.x.

Example (no Dropwizard-specific classes whatsoever):

import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;

import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.util.List;
import java.util.UUID;

import static org.junit.Assert.assertEquals;

public class Issue3435 extends JerseyTest {
    @Override
    protected Application configure() {
        return new ResourceConfig(TestResource.class);
    }

    @Test
    public void emptyStringQueryParamReturnsListWithOneNullElement() {
        Response response = target("test")
            .queryParam("list", "")
            .request()
            .get();
        assertEquals(200, response.getStatus());
        assertEquals("1: [null]", response.readEntity(String.class));
    }

    @Test
    public void missingQueryParamReturnsEmptyList() {
        Response response = target("test")
            .request()
            .get();
        assertEquals(200, response.getStatus());
        assertEquals("0: []", response.readEntity(String.class));
    }

    @Test
    public void filledQueryParamReturnsListWithOneElement() {
        Response response = target("test")
            .queryParam("list", "ec0cf621-d744-4a1c-b1d8-4b8a44b3dad7")
            .request()
            .get();
        assertEquals(200, response.getStatus());
        assertEquals("1: [ec0cf621-d744-4a1c-b1d8-4b8a44b3dad7]", response.readEntity(String.class));
    }

    @Path("test")
    public static class TestResource {
        @GET
        public String test(@QueryParam("list") List<UUID> list) {
            return list.size() + ": " + list.toString();
        }
    }
}

A similar issue has been filed for Jersey in eclipse-ee4j/jersey#563, but it looks like the behavior has changed again.

Would you mind filing an issue at https://github.com/eclipse-ee4j/jersey/issues to sort this out?

@github-actions github-actions bot added the stale Stale issue or pull request which will be closed soon label Nov 26, 2020
@joschi joschi added blocked bug and removed question stale Stale issue or pull request which will be closed soon labels Dec 15, 2020
@dropwizard dropwizard deleted a comment from github-actions bot Dec 15, 2020
@joschi joschi reopened this Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants