-
Notifications
You must be signed in to change notification settings - Fork 747
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
Warn about use of String charset methods #941
Conversation
CI fails due to #942. |
Using typed Charset methods avoids unneeded UnsupportedEncodingException handling.
For a while using the typed charset was about 15% slower than using the string charset, has this gone away? I know people were explicitly using string methods because of this before. |
@madrob Can you provide a reference? https://blog.codecentric.de/en/2014/04/faster-cleaner-code-since-java-7/ |
Sure, here's experimental results from several communities: https://issues.apache.org/jira/browse/LOG4J2-935 <-- description claims Java 6, 7, and 8 affected, benchmark shows only 6? Unsure what to make of these results, I figured to run my own jmh tests. https://gist.github.com/madrob/f0688f7148aa66a5406ce1b0fc1964c9 The charset usage is slower but within the error bounds for single encoding and much worse for various encodings (an idea borrowed from the blog post you link). Edit: And much faster in Java 9! |
(Sorry for the extremely slow response to this PR.) Warning on these APIs SGTM overall. I think it would be nice to have a suggested fix. If the charset is a string literal, we could recommend the corresponding Also, this might be worth splitting out into a separate check from |
Related to #941 PiperOrigin-RevId: 567623165
Related to #941 PiperOrigin-RevId: 567623165
Related to #941 PiperOrigin-RevId: 567719035
I added a separate check with a suggested fix in 1147184 |
@cushon, this new pattern only covers Would it make sense to cover some other common methods and constructors which take a string charset name as well, at least Here is SonarSource's corresponding implementation, though I guess covering all of these cases is out of scope for Error Prone; especially since some of those methods and constructors might be used quite rarely. |
@Marcono1234 yep, it's just those two APIs for now. I think covering more APIs definitely makes sense, I'd be happy to review PRs for that. |
Using typed
Charset
methods avoids unneededUnsupportedEncodingException
handling.