Skip to content

Fix MDSL generation with empty protected regions (#219) - #389

Draft
stefan-ka wants to merge 1 commit into
masterfrom
fix/219-empty-protected-region
Draft

stefan-ka wants to merge 1 commit into
masterfrom
fix/219-empty-protected-region

Conversation

@stefan-ka

@stefan-ka stefan-ka commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Fixes the exception reported in #219.

Cause

ProtectedRegionReader.getProtectedRegionContent computed the region content as
substring(start + startMarker.length() + lineSeparator, end - lineSeparator).

  • If the end marker directly follows the start marker (empty region, as in the issue), the begin index is greater than the end index → StringIndexOutOfBoundsException.
  • It assumed System.lineSeparator(); MDSL files with other line endings (e.g. CRLF on Linux, LF on Windows) were cut wrongly.

Fix

The content is now taken from after the line break of the start line up to the line break before the end marker, using the line breaks actually present in the file (\n or \r\n). An empty region returns "". Content and behavior for regular regions are unchanged (existing tests pass).

As before, the generator omits a region whose content is empty (the template checks ?has_content); that's the "region disappears" observation in the issue comments and is not changed here.

Tests

New tests in ProtectedRegionReaderTest: empty region, region with only an empty line, CRLF line endings. Without the fix, the empty-region and CRLF tests fail; with the fix all 67 MDSL/protected-region tests pass.

Not addressed

The comment about line breaks in vision statements producing invalid MDSL is a separate problem.

Based on master plus the Gradle/Jacoco build fix from #383 (cherry-picked), so it can be merged independently.

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.8%. Comparing base (17d16de) to head (2c684ad).

Files with missing lines Patch % Lines
...pper/dsl/generator/mdsl/ProtectedRegionReader.java 83.3% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             master    #389     +/-   ##
==========================================
- Coverage      91.8%   91.8%   -0.1%     
- Complexity     2230    2233      +3     
==========================================
  Files           211     211             
  Lines          5942    5949      +7     
  Branches        807     809      +2     
==========================================
+ Hits           5458    5464      +6     
- Misses          230     231      +1     
  Partials        254     254             

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

If the end marker of a protected region directly followed the start
marker, the computed substring indices overlapped and the MDSL generator
failed with a StringIndexOutOfBoundsException. The reader also assumed
the platform line separator, which broke files with other line endings.

The content between the markers is now determined via the line breaks
actually present in the file; an empty region returns an empty string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant