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

ServerRuntime.mapException() throws NullPointerException for NotFoundException default constructor #4171

Closed
geoffreyharding opened this issue Jun 19, 2019 · 3 comments · Fixed by #5507
Assignees

Comments

@geoffreyharding
Copy link

There is a missing check for null in org.glassfish.jersey.server.ServerRuntime.java in mapException():

    waeResponse = webApplicationException.getResponse();
    if (waeResponse.hasEntity()) {

Corresponds to line 514 in version 2.28

A NullPointerException can be thrown here for any WebApplicationExceptions with a null response. The easiest repro is to throw a NotFoundException using the default constructor.
Example:

	@GET
	@Path("/test")
	public void testGet()
	{
		throw new javax.ws.rs.NotFoundException();
	}
@jansupol
Copy link
Contributor

How did you manage not to have a Response?

        NotFoundException exception = new NotFoundException();
        Assert.assertNotNull(exception.getResponse());

@jansupol jansupol self-assigned this Aug 29, 2019
@okarpukhin
Copy link

I've faced the same issue in one of my tests using mockito (v5.8.0):

        when(mockFooService.barMethod()).thenThrow(NotFoundException.class);

Mockito somehow creates an instance of NotFoundException without a Response.

If I pass an instance of NotFoundException (instead of class), the test works as expected:

        when(mockFooService.barMethod()).thenThrow(new NotFoundException());

@jansupol
Copy link
Contributor

jansupol commented Jan 2, 2024

A user-defined subclass of WebApplicationException might return null, correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants