Skip to content

fix(spotless/gradle-plugin): Fix StringIndexOutOfBoundsException in scenarios where copyright year is surrounded by whitespace#2973

Open
Maciej-Sitarz-IBM wants to merge 6 commits into
diffplug:mainfrom
Maciej-Sitarz-IBM:msitarz/issue/copyright_year_with_whitespace
Open

fix(spotless/gradle-plugin): Fix StringIndexOutOfBoundsException in scenarios where copyright year is surrounded by whitespace#2973
Maciej-Sitarz-IBM wants to merge 6 commits into
diffplug:mainfrom
Maciej-Sitarz-IBM:msitarz/issue/copyright_year_with_whitespace

Conversation

@Maciej-Sitarz-IBM

Copy link
Copy Markdown

Summary

When the line with Copyright year in the source file matches the one in the license header template, but the year number is surrounded with whitespace the code fails with StringIndexOutOfBoundsException exception:

2 actionable tasks: 2 executed
> Task :spotlessJava
> Task :spotlessJavaApply FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':spotlessJavaApply'.
> There were 1 lint error(s), they must be fixed or suppressed.
  src/main/java/pkg/Test.java:LINE_UNDEFINED com.diffplug.spotless.generic.LicenseHeaderStep(java.lang.StringIndexOutOfBoundsException) begin 8, end 7, length 7 (...)
  Resolve these lints or suppress with `suppressLintsFor`

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':spotlessJavaApply'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:149)
	at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:147)

(...)

Caused by: org.gradle.api.GradleException: There were 1 lint error(s), they must be fixed or suppressed.
src/main/java/pkg/Test.java:LINE_UNDEFINED com.diffplug.spotless.generic.LicenseHeaderStep(java.lang.StringIndexOutOfBoundsException) begin 8, end 7, length 7 (...)
Resolve these lints or suppress with `suppressLintsFor`
	at com.diffplug.gradle.spotless.SpotlessApply.performAction(SpotlessApply.java:60)
(...)

Changes

  1. Added unit test cases that test scenarios with year and year ranges having white-space before/after the year string. These tests reproduce the issue (first commit).
  2. Implemented the fix for the failing cases (second commit).
  3. Added info to changelogs (third commit).

@Maciej-Sitarz-IBM

Maciej-Sitarz-IBM commented Jun 12, 2026

Copy link
Copy Markdown
Author

This PR topic needs to be edited, as this fix is not only related to spotless/gradle-plugin.

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