payara / Payara

Payara Server is an open source middleware platform that supports reliable and secure deployments of Java EE (Jakarta EE) and MicroProfile applications in any environment: on premise, in the cloud or hybrid.
http://www.payara.fish
Other
880 stars 302 forks source link

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

Open elcodedocle opened 1 month ago

elcodedocle commented 1 month ago

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:

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 commented 1 month ago

( Application level workaround we are introducing until the issue is fixed, just for the custom ValidationExceptionMapper: https://github.com/elcodedocle/payara-sscce/commit/0fd3bc2fbbeadd023eef563e844243b03e36d5d2 )

Elifzeynepedman commented 1 month ago

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

elcodedocle commented 1 month ago

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:

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 commented 1 month ago

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