Skip to content

SONARJAVA-6269 S1451: Rollback to empty default headerFormat#5588

Merged
NoemieBenard merged 1 commit intomasterfrom
nb/S1451-rollback-to-empty-default-header
Apr 29, 2026
Merged

SONARJAVA-6269 S1451: Rollback to empty default headerFormat#5588
NoemieBenard merged 1 commit intomasterfrom
nb/S1451-rollback-to-empty-default-header

Conversation

@NoemieBenard
Copy link
Copy Markdown
Contributor

Replace the template header with an empty string to allow setting an empty header in SQ quality profile.

@hashicorp-vault-sonar-prod
Copy link
Copy Markdown
Contributor

hashicorp-vault-sonar-prod Bot commented Apr 29, 2026

SONARJAVA-6269

@sonar-review-alpha
Copy link
Copy Markdown
Contributor

sonar-review-alpha Bot commented Apr 29, 2026

Summary

Changes the S1451 rule's default header format from a multi-line template (with product/copyright placeholders) to an empty string. This enables SonarQube quality profiles to use empty headers without requiring explicit configuration overrides. Test cleanup removes now-redundant explicit headerFormat = "" assignments since that matches the new default.

What reviewers should know

Key file: FileHeaderCheck.java (lines 34–35) — the default is changed from a 7-line template to "".

Behavior impact: When the S1451 rule is applied without a custom headerFormat configured in the quality profile, it will now default to no header requirement instead of prompting users to configure it. Users who have explicitly set a header format in their profiles are unaffected.

Test changes: Removes manual headerFormat = "" assignments from two test cases since they now inherit the empty default — simple cleanup, no behavioral change.

Verify: Check that the two removed test assignments (lines 103 and 110) were only for testing the empty-header case and don't mask any other test expectations.


  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

@sonarqube-next
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@sonar-review-alpha sonar-review-alpha Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✅

Clean, minimal change. The empty-string default correctly disables the rule until a header is configured — headerFormat.isEmpty() triggers checkExpectedLines(new String[]{}), which always passes the matches() check (0 <= lines.size()). No regressions for users who have already configured a custom header.

One follow-up worth doing (not a blocker): ClassDefaultHeader.java (unchanged) still contains the old placeholder template and carries the comment // Compliant (default header). With the empty default, the test at lines 114–118 now trivially passes for any file, making both the test fixture's content and that test case redundant with the ClassBlankLine/ClassNoBlankLine cases just above. Consider replacing ClassDefaultHeader.java with a bare Java file and renaming it to something like ClassAnyContent.java, or dropping the test case entirely.

🗣️ Give feedback

@NoemieBenard NoemieBenard merged commit dad07e8 into master Apr 29, 2026
18 checks passed
@NoemieBenard NoemieBenard deleted the nb/S1451-rollback-to-empty-default-header branch April 29, 2026 14:43
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