-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix NullPointerException that would occur when WebApplicationException was thrown with an unassigned Http Status Code #443
Conversation
If you're using custom HTTP status codes why won't you write custom mappers for them 🤔 ? Those are designed for such cases. I don't see a reason putting logic in generic mapper that handle non-generic scenarios. Or do I miss something? |
That is certainly an option. The reason for this PR is because the nullpointer that happened in WebApplicationExceptionMapper would bypass the entire problem response mapping. It is my understanding that all responses should be mapped to a problem, when using this library. If the concensus is for handling such cases in custom mappers, just let me know, and I will close this PR. |
@lwitkowski: This part is very early code and if I correctly remember we consciously made a decison to keep
If it will be me I'd move everything custom to custom mappers. |
Thanks for contribution @JacobOJ !
We didn't want to introduce custom ENUM for custom codes, that's correct. And we're talking about generic I personally don't think our extension should throw NPE in any case, it should always end up in a
|
If we're to make such adjustment I'd like to understand from where this custom HTTP status code comes from. Cause the only scenarios I see are:
Plain |
Fully agree. I still think our extension should not throw NPEs
Pardon, I wasn't very clear about status code in this specific case: I'd pass status code that is defined in the exception. My take on 500 was more general approach that IMO we should be defensive and not cause NPEs throw by the code in this extension. Simply
That's something to consider, although I would not WARN about it more than once to be frank. |
We agree on NPE - should not be there. And fact that we re-discuss different options is exact reason why at first we tried to keep it "stupid simple" 😉 . I'd strongly vote for default behaviour of this extension NOT to propagate custom HTTP codes and go defensive way with Let me give example. If this is due to RestClient and someone at source system changes eg. If we'd start throwing meaningful Just a hypothetical scenario. |
IMO
The more I think about it, the less confident I am that there is any distinction between standard and custom http code at all. Is 418 custom or standard? Or 422? The latter is listed on mozilla.org, but is not implemented by JaxRS's Interestingly what I've just found out - Quarkus implementaiton of exception mapper for WebAppException has the same issue and will throw NPE for codes not implemented by IMO the most elastic for programmers, robust, yet without increasing complexity of this extension implementation for this mapper would be:
I get your point, but who are we to decide to ban 492 codes and translate them to 500s? Again, I don't think there's any standard that would justify this rigidness.
That's veeery hypothetical scenario, don't you think? And even if - why none of the JaxRS implementations (or any other servlet impl) behave like you suggest by 'banning' non standard codes and translating them to internal server error? |
For the record: #287 If I read our comments correctly, we didn't want to introduce At least I wasn't in favour of edit: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml - this seems to be an |
We don't ban them. We inform users of this extension that there is some non-standard error code so that they make consious decision what to do with this - by means of writing a mapper. What I'm stating is just that: With such a long discussion I forsee we may need to settle with:
What do you think about ☝️ ? (have no attachement to property name, but preference on |
The fact you would not use them doesn't mean others can't use them. And this extension should not get in the way by throwing NPEs or rewriting perfectly valid but @pazkooda Can you define (and back it up with some widely accepted RFC) what 'standard' and 'non-standard' code means please? Otherwise this discussion leads to nowhere. I've spent significant amount of time lately reading about this, I've provided multiple links, and pointed out differences between I (incorrectly) used this term in the past as well, but I'm now convinced it's a wrong term to call |
At first let me quote myself:
Note quotation marks and wink eye. I'm not oracle in this topic 😝. But actually now that you ask I can point to place which aggregates codes that are defined by (at least) some kind of standard with RFC9110 being "base one". It is this Wikipedia page (note that each "standard" code has respective RFC/etc attached to it). This is what I mean when use word non-standard Yet again - I state my preference.
The fact it is valid does not neglect fact it is not defined by any standard and it confuses client code. Basically source system can start sliently breaking my OpenAPI if I'm not careful enough with handling of Note on Edit:
That is why I'd like to have this monitoring explicit. If I find such |
None of these say using 479 is invalid, forbidden, discouraged etc. None suggest to map it to 500 status. And IANA (refered by many RFCs) seems to be much better source of truth than wikipedia.
Unassigned are defined as 'valid' by HTTP standard itself.
I don't think we can reasonably prevent NPEs outside of this extension, IMO we shouldn't even try, especially with hiding real cause from api clients. Which bug report is easier to debug:
What's more explicit and can point to e.g upstream system immediately without looking at logs or proxy code? I really see zero reason, zero added value for this mapping, yet I see some downsides.
In such setup, you - as developer - should have try-catch and catch WebAppExceptions around you RestClient and act accordingly. And setup monitoring for this part of application.
I'm also leaning towards still using it, but I'm strongly against mapping everything that is not on this arbitrary list to http 500.
I think there's some confusion here - there's no such thing as a mapper for http code. There's a mapper for exception type. |
runtime/src/main/java/io/quarkiverse/resteasy/problem/jaxrs/WebApplicationExceptionMapper.java
Show resolved
Hide resolved
integration-test/src/test/java/io/quarkiverse/resteasy/problem/JaxRsMappersIT.java
Outdated
Show resolved
Hide resolved
@JacobOJ I've made 2 suggestions to simplify the change a bit, would you be ok with these? @pazkooda please have a look at the changes after my suggestions are applied - it will get rid of NPE with one very small and limited change in the codebase. Asserted value of "Unknown code" comes from JaxRs impl (but not I suggest we park or extract the discussion about mapping |
…n was thrown with an unassigned Http Status Code
@lwitkowski Yes, nice changes. I have updated the PR with your suggestions as well as updated the name of the test to say |
LGTM, thanks again for contribution @JacobOJ , I'll probably release new minor version later today. |
Thank you, too. Looking forward to the new release. |
v3.15.0 has just landed in maven central: https://repo1.maven.org/maven2/io/quarkiverse/resteasy-problem/quarkus-resteasy-problem/3.15.0/ |
At my company, some endpoints return non-standard HTTP Status Codes.
These cause
WebApplicationExceptionMapper
to throw a NullPointerException becauseResponse.StatusType status = Response.Status.fromStatusCode(statusCode);
returns null and thenstatus.getReasonPhrase())
throws the exception.This ultimate results in the error not being mapped to a HttpProblem.
This PR fixes that by setting the title of the problem to
Unknown HTTP Status Code
instead, if the above fails.