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

Bug Report: JAX-RS Remapping of wrapped exceptions using a custom mapper not working anymore/ FISH-9727 #6828

Open
elcodedocle opened this issue Jul 19, 2024 · 5 comments
Assignees
Labels
Status: Accepted Confirmed defect or accepted improvement to implement, issue has been escalated to Platform Dev Type: Bug Label issue as a bug defect

Comments

@elcodedocle
Copy link

elcodedocle commented Jul 19, 2024

Brief Summary

Up until Payara 6.2024.1, whenever a custom JAX-RS ExceptionMapper (E.g. EJBExceptionMapper) would handle an exception (E.g. EJBException) wrapping another exception (E.g. ValidationException) mapped by another custom mapper (E.g. a custom ValidationExceptionMapper); the custom mapper (E.g. EJBExceptionMapper) would be able to:

  1. Pick up that exception (E.g. EJBException)
  2. Unwrap the inner one (E.g. ValidationException)
  3. Have that other custom mapper handle it (E.g. a custom ValidationExceptionMapper)

This would produce the appropriate custom JAX-RS error response for that wrapped exception.

This is not the case anymore. Instead, the default mapper is selected over the custom one when requesting the mapper for the wrapped exception (E.g. via Providers.getExceptionMapper(ValidationException.class)). This results in a default error response for the wrapped exception, where the custom one was expected.

We have a reproducer on https://github.com/elcodedocle/payara-sscce/tree/payara-issue-6828:

(It is not as minimal as it could be; Please ignore the storage layer)

Running mvn clean verify on this project will deploy and run tests on the Payara version specified in the pom.xml file:

  • Deploys an application with 2 endpoints that throw the same ValidationException.
    • One of these endpoints throws the ValidationException within an EJB transaction on a @Singleton EJB, so it is wrapped within an EJBException.
      • And subsequently captured by the custom EJBExceptionMapper defined on the project.
      • The custom EJBExceptionMapper will unwrap & handle the ValidationException wrapped on the EJBException, using the ValidationExceptionMapper resolved from the injected @Context through providers.getExceptionMapper((Class<Throwable>) unwrappedValidationException.getClass()) (Where unwrappedValidationException.getClass() resolves to ValidationException.class).
    • The other endpoint throws the ValidationException on the JAX-RS resource itself, so it is not wrapped.
    • The project also includes a custom ValidationExceptionMapper that should return a BAD_REQUEST 400 status response when mapping the ValidationException, for both endpoints.
  • Runs integration tests for the 2 endpoints throwing exceptions.

The test for the endpoint that throws the wrapped exception will fail as described, for Payara 2024.1 and later.

The "control" test for the endpoint that throws the unwrapped exception will pass on any Payara version.

Expected Outcome

Exceptions unwrapped by custom mappers are handled by custom mappers that map them.

Current Outcome

Exceptions unwrapped by custom mappers are not captured by custom mappers that map them; a generic default error response from the default mapper is issued instead.

Reproducer

https://github.com/elcodedocle/payara-sscce/tree/payara-issue-6828

Operating System

Latest Debian 12 bookworm official Docker image

JDK Version

Latest OpenJDK 17 build from Debian 12 bookworm

Payara Distribution

Payara Server Full Profile

@elcodedocle elcodedocle added Status: Open Issue has been triaged by the front-line engineers and is being worked on verification Type: Bug Label issue as a bug defect labels Jul 19, 2024
@elcodedocle
Copy link
Author

( Application level workaround we are introducing until the issue is fixed, just for the custom ValidationExceptionMapper: elcodedocle/payara-sscce@0fd3bc2 )

@Elifzeynepedman
Copy link

Hi @elcodedocle,

I wasn't able to reproduce the error you're encountering. Could you please provide detailed steps on how to run the reproducer? This will help me ensure that I haven't missed any steps during my attempts to replicate the issue.

Thank you,
Elif

@Elifzeynepedman Elifzeynepedman added Status: Pending Waiting on the issue requester to give more details or share a reproducer and removed Status: Open Issue has been triaged by the front-line engineers and is being worked on verification labels Aug 9, 2024
@elcodedocle
Copy link
Author

elcodedocle commented Aug 9, 2024

Hi Elif,

Running mvn clean verify on this project will deploy and run tests on the Payara version specified in the pom.xml file.

git clone --single-branch --branch payara-issue-6828 https://github.com/elcodedocle/payara-sscce
cd payara-sscce
mvn clean verify

Requirements:

  • JDK 17 (tested on OpenJDK 17.0.12)
  • Maven 3.9 (tested on 3.9.8)
  • Recent Docker (tested on 27.0.3 engine bundled with 4.32.0 docker desktop for Mac)

Files of interest:

You should be able to connect a JVM debugger to the exposed ${debug.port}, but you may have to delay execution of tests to connect before they run after the environment is deployed.

To be clear: The observed deviation is that we expect ValidationExceptionMapper to be obtained here, as it happened in previous Payara releases, but that is not the case anymore; Instead, we get the default one.

Best regards,

@elcodedocle
Copy link
Author

Evidence from running the reproducer:

Before 6.2004.1 (E.g. Payara 6.2023.12), we get the expected com.example.payara.hello.ValidationExceptionMapper:
Screenshot 2024-08-09 at 18 32 48

Since 6.2004.1, we get the default org.glassfish.jersey.server.validation.internal.ValidationExceptionMapper instead:
Screenshot 2024-08-09 at 18 29 58

@elcodedocle elcodedocle changed the title Bug Report: JAX-RS Remapping of rethrown exceptions not working anymore Bug Report: JAX-RS Remapping of wrapped exceptions not working anymore Aug 10, 2024
@elcodedocle elcodedocle changed the title Bug Report: JAX-RS Remapping of wrapped exceptions not working anymore Bug Report: JAX-RS Remapping of wrapped exceptions using a custom mapper not working anymore Aug 10, 2024
@Elifzeynepedman Elifzeynepedman added Status: Open Issue has been triaged by the front-line engineers and is being worked on verification and removed Status: Pending Waiting on the issue requester to give more details or share a reproducer labels Aug 15, 2024
@Elifzeynepedman
Copy link

Hi @elcodedocle,

I was able to reproduce the issue and I have escalated this to the platform development team as FISH-9727.

Thank you,
Elif

@Elifzeynepedman Elifzeynepedman added Status: Accepted Confirmed defect or accepted improvement to implement, issue has been escalated to Platform Dev and removed Status: Open Issue has been triaged by the front-line engineers and is being worked on verification labels Sep 16, 2024
@Elifzeynepedman Elifzeynepedman changed the title Bug Report: JAX-RS Remapping of wrapped exceptions using a custom mapper not working anymore Bug Report: JAX-RS Remapping of wrapped exceptions using a custom mapper not working anymore/ FISH-9727 Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Confirmed defect or accepted improvement to implement, issue has been escalated to Platform Dev Type: Bug Label issue as a bug defect
Projects
None yet
Development

No branches or pull requests

2 participants