Add UnnecessarySubstring for regions parsed via Integer.parseInt. - #6000
Open
gaul wants to merge 1 commit into
Open
Add UnnecessarySubstring for regions parsed via Integer.parseInt.#6000gaul wants to merge 1 commit into
UnnecessarySubstring for regions parsed via Integer.parseInt.#6000gaul wants to merge 1 commit into
Conversation
`Integer.parseInt(String)` and its siblings force callers to materialize the region they parse. Since JDK 9 each has a `(CharSequence, int, int, int)` overload that reads the region in place, so the copy is pure overhead. Covers the four parses that have that overload: `Integer.parseInt`, `Integer.parseUnsignedInt`, `Long.parseLong` and `Long.parseUnsignedLong`. `Double.parseDouble`, `Integer.valueOf` and `Integer.decode` have none. The overload is resolved on the owning symbol rather than inferred from the source level, so `--release 8` compilations report nothing. `s.substring(begin)` needs `s.length()` in the replacement, which repeats the target, so that form is only rewritten when the target is an identifier, a literal, or a side-effect-free field or array access. Run over sources jars for ~100 widely used Maven Central artifacts (54,690 files), this reports 100 occurrences in 18 of them, including commons-lang3, h2, hsqldb, lucene-core and jgit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Integer.parseInt(String)and its siblings force callers to materialize the region they parse. Since JDK 9 each has a(CharSequence, int, int, int)overload that reads the region in place, so the copy is pure overhead.Covers the four parses that have that overload:
Integer.parseInt,Integer.parseUnsignedInt,Long.parseLongandLong.parseUnsignedLong.Double.parseDouble,Integer.valueOfandInteger.decodehave none. The overload is resolved on the owning symbol rather than inferred from the source level, so--release 8compilations report nothing.s.substring(begin)needss.length()in the replacement, which repeats the target, so that form is only rewritten when the target is an identifier, a literal, or a side-effect-free field or array access.Run over sources jars for ~100 widely used Maven Central artifacts (54,690 files), this reports 100 occurrences in 18 of them, including commons-lang3, h2, hsqldb, lucene-core and jgit.