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

Fix adding license header to files larger than 2048 bytes #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joschi
Copy link
Contributor

@joschi joschi commented Jul 29, 2021

The BufferedReader in PreparedCommentHeader#update() is initialized with a read-ahead limit of 2048 bytes.

If a file is larger than that, the mark will be invalidated while the update() method skips through the file line-by-line and when no valid existing license header was detected, the BufferedReader#reset() method will fail.

java.io.IOException: Mark invalid
	at java.base/java.io.BufferedReader.reset(BufferedReader.java:517)
	at java_io_BufferedReader$reset$1.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119)
	at org.cadixdev.gradle.licenser.header.PreparedCommentHeader$_update_closure2.doCall(PreparedCommentHeader.groovy:84)

The `BufferedReader` in `PreparedCommentHeader#update()` is initialized with a read-ahead limit of 2048 bytes.

If a file is larger than that, the mark will be invalidated while the `update()` method skips through the file line-by-line and when no valid existing license header was detected, the `BufferedReader#reset()` method will fail.

```text
java.io.IOException: Mark invalid
	at java.base/java.io.BufferedReader.reset(BufferedReader.java:517)
	at java_io_BufferedReader$reset$1.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119)
	at org.cadixdev.gradle.licenser.header.PreparedCommentHeader$_update_closure2.doCall(PreparedCommentHeader.groovy:84)
```
@joschi
Copy link
Contributor Author

joschi commented Jul 29, 2021

The failing tests on Travis CI are unrelated to this PR.

org.cadixdev.gradle.licenser.LicenserPluginFunctionalTest > supports Kotlin buildscripts (gradle 6.8.3) FAILED

    org.gradle.testkit.runner.UnexpectedBuildFailure at LicenserPluginFunctionalTest.groovy:431

org.cadixdev.gradle.licenser.LicenserPluginFunctionalTest > supports Kotlin buildscripts (gradle 6.8.3) FAILED

    org.gradle.testkit.runner.UnexpectedBuildFailure at LicenserPluginFunctionalTest.groovy:431

org.cadixdev.gradle.licenser.LicenserPluginFunctionalTest > supports Kotlin buildscripts (gradle 6.9) FAILED

    org.gradle.testkit.runner.UnexpectedBuildFailure at LicenserPluginFunctionalTest.groovy:431

60 tests completed, 3 failed

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.

1 participant