René's URL Explorer Experiment


Title: Inconsistent result of failed Base64.decode (throws vs returns null) · Issue #65 · patrickfav/bytes-java · GitHub

Open Graph Title: Inconsistent result of failed Base64.decode (throws vs returns null) · Issue #65 · patrickfav/bytes-java

X Title: Inconsistent result of failed Base64.decode (throws vs returns null) · Issue #65 · patrickfav/bytes-java

Description: When Base64.decode(CharSequence in) decodes a string, in some cases for "bad" strings in throws IllegalArgumentException: bytes-java/src/main/java/at/favre/lib/bytes/Base64.java Line 92 in e622b3b throw new IllegalArgumentException("inva...

Open Graph Description: When Base64.decode(CharSequence in) decodes a string, in some cases for "bad" strings in throws IllegalArgumentException: bytes-java/src/main/java/at/favre/lib/bytes/Base64.java Line 92 in e622b3b ...

X Description: When Base64.decode(CharSequence in) decodes a string, in some cases for "bad" strings in throws IllegalArgumentException: bytes-java/src/main/java/at/favre/lib/bytes/Base64.java Line 92 i...

Opengraph URL: https://github.com/patrickfav/bytes-java/issues/65

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent result of failed Base64.decode (throws vs returns null)","articleBody":"When `Base64.decode(CharSequence in)` decodes a string, in some cases for \"bad\" strings in throws `IllegalArgumentException`:\r\n\r\nhttps://github.com/patrickfav/bytes-java/blob/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a/src/main/java/at/favre/lib/bytes/Base64.java#L92\r\n\r\n, but in other cases it returns `null`.\r\n\r\nhttps://github.com/patrickfav/bytes-java/blob/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a/src/main/java/at/favre/lib/bytes/Base64.java#L108-L110\r\n\r\nThis makes the method harder to use as the caller needs to handle both cases for every call with potentially invalid input: catching `IllegalArgumentException` and comparing the result with `null`.\r\nI think the best way to handle both types of invalid input would be to throw `IllegalArgumentException` in both cases and never return `null`.\r\n\r\nThis behavior is even tested:\r\n\r\nhttps://github.com/patrickfav/bytes-java/blob/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a/src/test/java/at/favre/lib/bytes/Base64Test.java#L47\r\n\r\nIt makes me think that this is the desired behavior, but why?\r\n\r\nBtw, this behavior actually leads to the bug in the `id-mask` library. That is how I actually found it.\r\nWhen I do `idMask.unmask(badlyEncodedString)`, then it eventually calls `Base64.decode`, that returns `null`, and then it tries to wrap it into `Bytes` object\r\n\r\nhttps://github.com/patrickfav/bytes-java/blob/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a/src/main/java/at/favre/lib/bytes/Bytes.java#L155-L157\r\n\r\n, that leads to `java.lang.NullPointerException: passed array must not be null`. That is unexpected behavior I believe. `idMask.unmask(badlyEncodedString)` should never throw NPE.\r\n\r\nOf course, this problem could be solved on the `id-mask` side (by catching NPE and throwing `IllegalArgumentException`), but I think the root problem is the inconsistent behavior of `Base64.decode`. I can't imagine a situation when it is the desired behavior to sometimes throw `IllegalArgumentException` and sometimes return `null` for basically the same case of \"invalid input\".\r\n\r\nWhy it is important to throw `IllegalArgumentException` and not `NullPointerException`? Because the 1st error means the error is on the caller side (probably someone called the API with a wrong encoded ID), while the 2nd one means that something wrong happened inside the library. NPE would probably be acceptable in the case when `input` CharSequence is `null`. But if it is a non-null string, then NPE should never be thrown except for a bug in the implementation.","author":{"url":"https://github.com/xak2000","@type":"Person","name":"xak2000"},"datePublished":"2024-03-20T17:53:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/65/bytes-java/issues/65"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:5abebecb-5d13-b892-a406-9549f922dbf8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD10A:2C1011:6D78DAD:9089FAD:696DD884
html-safe-nonceee03ab8ef056703ff98dbd5d3d4dfc3656dfb4d1af882748b8eb2f23095d88dc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTBBOjJDMTAxMTo2RDc4REFEOjkwODlGQUQ6Njk2REQ4ODQiLCJ2aXNpdG9yX2lkIjoiNjY4MDkxODI4ODkzNTgwMzAxMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9745e05e9721c04050f8dcaa8314e6e05838e323c03b0aa99f88778d98051ac4
hovercard-subject-tagissue:2198188005
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/patrickfav/bytes-java/65/issue_layout
twitter:imagehttps://opengraph.githubassets.com/585380464b3f162e7f5aee22f9368a2f29fb10a1808d7f351b1daca967150a23/patrickfav/bytes-java/issues/65
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/585380464b3f162e7f5aee22f9368a2f29fb10a1808d7f351b1daca967150a23/patrickfav/bytes-java/issues/65
og:image:altWhen Base64.decode(CharSequence in) decodes a string, in some cases for "bad" strings in throws IllegalArgumentException: bytes-java/src/main/java/at/favre/lib/bytes/Base64.java Line 92 in e622b3b ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamexak2000
hostnamegithub.com
expected-hostnamegithub.com
None4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064
turbo-cache-controlno-preview
go-importgithub.com/patrickfav/bytes-java git https://github.com/patrickfav/bytes-java.git
octolytics-dimension-user_id2980711
octolytics-dimension-user_loginpatrickfav
octolytics-dimension-repository_id108965147
octolytics-dimension-repository_nwopatrickfav/bytes-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id108965147
octolytics-dimension-repository_network_root_nwopatrickfav/bytes-java
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7e5ae23c70136152637ceee8d6faceb35596ec46
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/patrickfav/bytes-java/issues/65#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpatrickfav%2Fbytes-java%2Fissues%2F65
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpatrickfav%2Fbytes-java%2Fissues%2F65
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=patrickfav%2Fbytes-java
Reloadhttps://patch-diff.githubusercontent.com/patrickfav/bytes-java/issues/65
Reloadhttps://patch-diff.githubusercontent.com/patrickfav/bytes-java/issues/65
Reloadhttps://patch-diff.githubusercontent.com/patrickfav/bytes-java/issues/65
patrickfav https://patch-diff.githubusercontent.com/patrickfav
bytes-javahttps://patch-diff.githubusercontent.com/patrickfav/bytes-java
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpatrickfav%2Fbytes-java
Fork 34 https://patch-diff.githubusercontent.com/login?return_to=%2Fpatrickfav%2Fbytes-java
Star 170 https://patch-diff.githubusercontent.com/login?return_to=%2Fpatrickfav%2Fbytes-java
Code https://patch-diff.githubusercontent.com/patrickfav/bytes-java
Issues 5 https://patch-diff.githubusercontent.com/patrickfav/bytes-java/issues
Pull requests 2 https://patch-diff.githubusercontent.com/patrickfav/bytes-java/pulls
Actions https://patch-diff.githubusercontent.com/patrickfav/bytes-java/actions
Projects 0 https://patch-diff.githubusercontent.com/patrickfav/bytes-java/projects
Wiki https://patch-diff.githubusercontent.com/patrickfav/bytes-java/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/patrickfav/bytes-java/security
Please reload this pagehttps://patch-diff.githubusercontent.com/patrickfav/bytes-java/issues/65
Insights https://patch-diff.githubusercontent.com/patrickfav/bytes-java/pulse
Code https://patch-diff.githubusercontent.com/patrickfav/bytes-java
Issues https://patch-diff.githubusercontent.com/patrickfav/bytes-java/issues
Pull requests https://patch-diff.githubusercontent.com/patrickfav/bytes-java/pulls
Actions https://patch-diff.githubusercontent.com/patrickfav/bytes-java/actions
Projects https://patch-diff.githubusercontent.com/patrickfav/bytes-java/projects
Wiki https://patch-diff.githubusercontent.com/patrickfav/bytes-java/wiki
Security https://patch-diff.githubusercontent.com/patrickfav/bytes-java/security
Insights https://patch-diff.githubusercontent.com/patrickfav/bytes-java/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/patrickfav/bytes-java/issues/65
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/patrickfav/bytes-java/issues/65
Inconsistent result of failed Base64.decode (throws vs returns null)https://patch-diff.githubusercontent.com/patrickfav/bytes-java/issues/65#top
https://github.com/xak2000
https://github.com/xak2000
xak2000https://github.com/xak2000
on Mar 20, 2024https://github.com/patrickfav/bytes-java/issues/65#issue-2198188005
bytes-java/src/main/java/at/favre/lib/bytes/Base64.javahttps://github.com/patrickfav/bytes-java/blob/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a/src/main/java/at/favre/lib/bytes/Base64.java#L92
e622b3bhttps://patch-diff.githubusercontent.com/patrickfav/bytes-java/commit/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a
bytes-java/src/main/java/at/favre/lib/bytes/Base64.javahttps://github.com/patrickfav/bytes-java/blob/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a/src/main/java/at/favre/lib/bytes/Base64.java#L108-L110
e622b3bhttps://patch-diff.githubusercontent.com/patrickfav/bytes-java/commit/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a
bytes-java/src/test/java/at/favre/lib/bytes/Base64Test.javahttps://github.com/patrickfav/bytes-java/blob/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a/src/test/java/at/favre/lib/bytes/Base64Test.java#L47
e622b3bhttps://patch-diff.githubusercontent.com/patrickfav/bytes-java/commit/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a
bytes-java/src/main/java/at/favre/lib/bytes/Bytes.javahttps://github.com/patrickfav/bytes-java/blob/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a/src/main/java/at/favre/lib/bytes/Bytes.java#L155-L157
e622b3bhttps://patch-diff.githubusercontent.com/patrickfav/bytes-java/commit/e622b3b4dfe0bca2b65d2dcd6dae78441ee2961a
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.