close
Skip to content

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

Closed
dweiss wants to merge 1 commit into
diffplug:mainfrom
dweiss:prettier-zero-length
Closed

Dodge StringIndexOutOfBoundsException on empty files (prettier/css)#751
dweiss wants to merge 1 commit into
diffplug:mainfrom
dweiss:prettier-zero-length

Conversation

@dweiss

@dweiss dweiss commented Dec 16, 2020

Copy link
Copy Markdown
Contributor

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

dweiss commented Dec 16, 2020

Copy link
Copy Markdown
Contributor Author

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

@nedtwigg

Copy link
Copy Markdown
Member

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

@dweiss

dweiss commented Dec 16, 2020

Copy link
Copy Markdown
Contributor Author

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

nedtwigg commented Jan 4, 2021

Copy link
Copy Markdown
Member

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

@nedtwigg nedtwigg closed this Jan 4, 2021
@nedtwigg

nedtwigg commented Jan 4, 2021

Copy link
Copy Markdown
Member

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