[go: nahoru, domu]

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

InvalidArgumentException from HttpResponse if the content-type is invalid #905

Closed
jmorrise opened this issue Dec 5, 2019 · 1 comment
Closed
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@jmorrise
Copy link
Contributor
jmorrise commented Dec 5, 2019

I'm hitting an edge case at HttpResponse.java#153: if the contentType of the response is invalid, an InvalidArgumentException is thrown while constructing the media type. My code makes an http request to read the contents of a file from Google Cloud Storage, so if the owner of the file has set an invalid content-type (which is easy to do in GCS, unfortunately), I can't read the file at all.

I understand that this might just be WAI, and I could just throw the error back to the user, however it would be nice if I could handle this gracefully and read the file contents as if the mediaType were unknown. It's difficult for me to catch and handle the error myself since I'm not calling this library directly (another library that I don't own is making the http request).

Since mediaType is nullable anyway, would it be reasonable behavior to set it to null if the contentType were invalid? Something like

mediaType = contentType == null || !HttpMediaType.isValid(contentType) ? null : new HttpMediaType(contentType);

where isValid would return true iff the contentType can be parsed to a valid mediaType.

Would this be an okay change? I wanted to check before actually sending a pull request. Thanks.

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Dec 6, 2019
@chingor13 chingor13 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 9, 2019
@chingor13
Copy link
Collaborator
chingor13 commented Dec 9, 2019

I think allowing this to be nullable is ok. It might be worth considering lazy loading the mediaType value as it's not critical to the contents of the instance.

Either way, I'm not sure of a time when you'd want to get a IllegalArgumentException (a runtime, unchecked exception) when parsing an HTTP response without a way to inspect the response.

@yoshi-automation yoshi-automation removed the triage me I really want to be triaged. label Dec 9, 2019
clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
…gleapis#1381) (googleapis#905)

* chore: Enable Size-Label bot in all googleapis Java repositories

Auto-label T-shirt size indicator should be assigned on every new pull request in all googleapis Java repositories

* Remove product

Remove product since it is by default true

* add license header

Co-authored-by: Neenu Shaji <Neenu1995@users.noreply.github.com>
Source-Link: googleapis/synthtool@54b2c6a
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:fc52b202aa298a50a12c64efd04fea3884d867947effe2fa85382a246c09e813

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Neenu Shaji <Neenu1995@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants