Skip to content

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

Merged
nedtwigg merged 6 commits into
diffplug:mainfrom
Maciej-Sitarz-IBM:msitarz/issue/copyright_year_with_whitespace
Jun 16, 2026
Merged

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

Conversation

@Maciej-Sitarz-IBM

Copy link
Copy Markdown
Contributor

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
Contributor Author

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

@nedtwigg nedtwigg merged commit 780f0f6 into diffplug:main Jun 16, 2026
20 checks passed
dongjoon-hyun added a commit to apache/spark-kubernetes-operator that referenced this pull request Jun 23, 2026
### What changes were proposed in this pull request?

This PR upgrades `spotless-plugin-gradle` to `8.7.0`.

### Why are the changes needed?

To use the latest release (`8.7.0`, released on 2026-06-16).
- https://github.com/diffplug/spotless/releases/tag/gradle/8.7.0
  - diffplug/spotless#2962
  - diffplug/spotless#2940
  - diffplug/spotless#2973

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.8

Closes #716 from dongjoon-hyun/SPARK-57629.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
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