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

Dodge StringIndexOutOfBoundsException on empty files (prettier/css) #751

Closed
wants to merge 1 commit into from

Conversation

dweiss
Copy link
Contributor

@dweiss dweiss commented Dec 16, 2020

Trivial fix for empty css files causing out-of-bounds exception with prettier:

> Task :dcs:contexts:frontend:spotlessJs
Step 'prettier-format' found problem in '...\SearchApp.css':
begin 0, end -1, length 0
java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 0
        at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3756)
        at java.base/java.lang.String.substring(String.java:1902)
        at com.diffplug.spotless.npm.PrettierFormatterStep$PrettierFilePathPassingFormatterFunc.applyWithFile(PrettierFormatterStep.java:116)
        at com.diffplug.spotless.FormatterFunc$NeedsFile.apply(FormatterFunc.java:154)

@dweiss
Copy link
Contributor Author

dweiss commented Dec 16, 2020

Not necessarily for immediate merging, but shows where the problem is (zero-length files).

@nedtwigg
Copy link
Member

Maybe if (unix.trim().isEmpty()) { return unix; }

@dweiss
Copy link
Contributor Author

dweiss commented Dec 16, 2020

Absolutely - any way is good to dodge that exception. 👍 Please feel free to correct this in the code directly, not worth a roundtrip on the PR. Thank you for the software, it's excellent.

@nedtwigg
Copy link
Member

nedtwigg commented Jan 4, 2021

Fixed in commit referenced above, thanks for finding bug and reporting.

@nedtwigg nedtwigg closed this Jan 4, 2021
@nedtwigg
Copy link
Member

nedtwigg commented Jan 4, 2021

Fixed in plugin-gradle 5.9.0 and plugin-maven 2.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants