Skip to content

GROOVY-11807: MapWithDefault can break type safety of key set#2641

Merged
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy11807
Jun 29, 2026
Merged

GROOVY-11807: MapWithDefault can break type safety of key set#2641
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy11807

Conversation

@paulk-asert

Copy link
Copy Markdown
Contributor

No description provided.

@codecov-commenter

codecov-commenter commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.5476%. Comparing base (a7d75a5) to head (a4b448b).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2641        +/-   ##
==================================================
+ Coverage     68.5420%   68.5476%   +0.0055%     
- Complexity      33730      33742        +12     
==================================================
  Files            1523       1523                
  Lines          127923     127936        +13     
  Branches        23251      23252         +1     
==================================================
+ Hits            87681      87697        +16     
+ Misses          32464      32460         -4     
- Partials         7778       7779         +1     
Files with missing lines Coverage Δ
.../codehaus/groovy/runtime/DefaultGroovyMethods.java 74.9933% <100.0000%> (+0.0401%) ⬆️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds key- and key/value-checked withDefault overloads for Map to prevent MapWithDefault auto-growth from silently inserting keys of an incompatible runtime type (GROOVY-11807), and introduces regression tests covering the new behavior.

Changes:

  • Introduce new DefaultGroovyMethods.withDefault(Map, Class, …) overloads that wrap the backing map with asChecked(...) before decorating with MapWithDefault.
  • Add a new regression test class verifying incompatible keys/values fail fast (including under @CompileStatic) while the plain withDefault remains lenient.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java Adds new key-checked and key/value-checked withDefault overloads built on asChecked.
src/test/groovy/bugs/Groovy11807.groovy Adds regression tests for GROOVY-11807 covering dynamic and static compilation scenarios.

Comment thread src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@testlens-app

testlens-app Bot commented Jun 29, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: a4b448b
▶️ Tests: 102126 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app.

@paulk-asert paulk-asert merged commit c1f1e5e into apache:master Jun 29, 2026
32 checks passed
@paulk-asert paulk-asert deleted the groovy11807 branch June 29, 2026 21:11
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.

3 participants