Description
I am deploying a project using spring-cloud-openfeign
on a Glassfish (Payara 5) application server. During deployment I get the following exception:
Exception while deploying the app [xyz] : The lifecycle method [destroy] must not throw a checked exception.
Related annotation information: annotation [@javax.annotation.PreDestroy()] on annotated element
[public void org.springframework.cloud.openfeign.FeignAutoConfiguration$HttpClientFeignConfiguration.destroy()
throws java.lang.Exception] of type [METHOD]
The lifecycle method [destroy] must not throw a checked exception. Related annotation information:
annotation [@javax.annotation.PreDestroy()] on annotated element
[public void org.springframework.cloud.openfeign.FeignAutoConfiguration$HttpClientFeignConfiguration.destroy()
throws java.lang.Exception] of type [METHOD]
[...]
Glassfish seems to check all included classes for validity, including classes from libraries within the WAR file. In this case, it refuses to proceed, because there are instances, where methods annotated with javax.annotation.PreDestroy
throw exceptions. I looked into this, and found two instances:
Looking at the documentation for @PreDestroy
I found the following:
Note: A PreDestroy interceptor method must not throw application exceptions, but it may be declared to throw checked exceptions including the java.lang.Exception if the same interceptor method interposes on business or timeout methods in addition to lifecycle events. If a PreDestroy interceptor method returns a value, it is ignored by the container.
If the method throws an unchecked exception it is ignored except in the case of EJBs where the EJB can handle exceptions.
My understanding is, that in general, any method annotated with @PreDestroy
should not throw exceptions, and if it does, it is ignored in most cases. I tried replacing the two mentioned classes with version where I caught the exception in a try-catch block, and removed it from the signature. I was successfully able to do the deployment with this modifcation.
Would it be possible to include this modification in the upstream? I am aware that using this framework on Glassfish is more of a border case, since GF has JAX-RX. Thank you for your consideration.