You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2026/06/29 00:39:57 UTC
[PR] GROOVY-11807: MapWithDefault can break type safety of key set [groovy]
paulk-asert opened a new pull request, #2641:
URL: https://github.com/apache/groovy/pull/2641
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-11807: MapWithDefault can break type safety of key set [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert merged PR #2641:
URL: https://github.com/apache/groovy/pull/2641
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-11807: MapWithDefault can break type safety of key set [groovy]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2641:
URL: https://github.com/apache/groovy/pull/2641#discussion_r3489911417
##########
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java:
##########
@@ -19155,6 +19155,61 @@ public static <K, V> Map<K, V> withDefault(Map<K, V> self, boolean autoGrow, boo
return MapWithDefault.newInstance(self, autoGrow, autoShrink, init);
}
+ /**
+ * Decorates the given Map with a default value supplied by a closure, as per
+ * {@link #withDefault(Map, Closure)}, but the returned map additionally enforces its
+ * key and value types at runtime. Looking up (and so auto-growing for) a key that is
+ * not an instance of {@code keyType} throws {@link ClassCastException} at the point of
+ * misuse, rather than silently inserting a wrong-typed key that only surfaces later
+ * (for example when reading {@code keySet()}). The check is provided by decorating an
+ * {@link #asChecked(Map, Class, Class) asChecked} view, so direct mutation such as
+ * {@code map[key] = value} is guarded too.
+ * <pre class="language-groovy">
+ * def m = [:].withDefault(Number, Object){ 42 }
+ * assert m[1] == 42 // a compatible key grows the map
+ * // m['x'] // would throw ClassCastException (incompatible key)
+ * </pre>
Review Comment:
The GroovyDoc example for the key+value checked overload uses `Object` as `valueType`, which effectively disables value checking and undermines the method’s stated purpose (runtime enforcement of both key and value types). Using a concrete `valueType` (e.g. `String`) and showing an incompatible value case would make the example accurate and less confusing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-11807: MapWithDefault can break type safety of key set [groovy]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2641:
URL: https://github.com/apache/groovy/pull/2641#issuecomment-4830395641
## ✅ All tests passed ✅
🏷️ Commit: a4b448b7f43240632cd49e7681236742cb540dbe
▶️ Tests: 102126 executed
⚪️ Checks: 31/31 completed
---
_Learn more about TestLens at [testlens.app](https://testlens.app)._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-11807: MapWithDefault can break type safety of key set [groovy]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2641:
URL: https://github.com/apache/groovy/pull/2641#issuecomment-4828113538
## 🚨 TestLens detected 1 failed test 🚨
Here is what you can do:
1) Inspect the test failures carefully.
2) If you are convinced that some of the tests are flaky, you can mute them below.
3) Finally, trigger a rerun by checking the rerun checkbox.
### Test Summary
#### [Build and test / lts \(17, windows-latest, 1\)](https://github.com/apache/groovy/actions/runs/28341597783/job/83956989614?pr=2641) > :test
| Test | Runs |
|---|---|
| AsyncAwaitTest > testAsyncSupportAnyReturnsFirstCompletion\(\) | ❌ |
🏷️ Commit: c1cfd7336b23005b8882fdadb65a9edfa17cf122
▶️ Tests: 49044 executed
🟡 Checks: 6/29 completed
### Test Failures
<details>
<summary><strong>AsyncAwaitTest > testAsyncSupportAnyReturnsFirstCompletion()</strong> (:test in <a href="https://github.com/apache/groovy/actions/runs/28341597783/job/83956989614?pr=2641">Build and test / lts (17, windows-latest, 1)</a>)</summary>
```
Assertion failed:
assert AsyncSupport.any(slow, fast) == 'fast'
| | | |
| | | false
| | GroovyPromise{completed}
| GroovyPromise{completed}
'slow'
at org.codehaus.groovy.runtime.InvokerHelper.createAssertError(InvokerHelper.java:400)
at TestScript187.run(TestScript187.groovy:7)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:553)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:588)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:572)
at groovy.test.GroovyAssert.assertScript(GroovyAssert.java:106)
at groovy.test.GroovyAssert.assertScript(GroovyAssert.java:96)
at groovy.AsyncAwaitTest.testAsyncSupportAnyReturnsFirstCompletion(AsyncAwaitTest.groovy:2171)
```
</details>
### Muted Tests
> [!NOTE]
> Checks are currently running using the configuration below.
Select tests to mute in this pull request:
🔲 AsyncAwaitTest > testAsyncSupportAnyReturnsFirstCompletion\(\) <!-- uniqueId=[engine:junit-jupiter]/[class:groovy.AsyncAwaitTest]/[method:testAsyncSupportAnyReturnsFirstCompletion()] -->
Reuse successful test results:
🔲 ♻️ Only rerun the tests that failed or were muted before
Click the checkbox to trigger a rerun:
🔲 **Rerun jobs**
---
_Learn more about TestLens at [testlens.app](https://testlens.app)._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-11807: MapWithDefault can break type safety of key set [groovy]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2641:
URL: https://github.com/apache/groovy/pull/2641#issuecomment-4828159106
## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2641?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 68.5476%. Comparing base ([`a7d75a5`](https://app.codecov.io/gh/apache/groovy/commit/a7d75a57117601c17687f0724ccd2f73016f4ebe?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`c1cfd73`](https://app.codecov.io/gh/apache/groovy/commit/c1cfd7336b23005b8882fdadb65a9edfa17cf122?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 5 commits behind head on master.
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/groovy/pull/2641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #2641 +/- ##
==================================================
+ Coverage 68.5420% 68.5476% +0.0055%
- Complexity 33730 33739 +9
==================================================
Files 1523 1523
Lines 127923 127936 +13
Branches 23251 23252 +1
==================================================
+ Hits 87681 87697 +16
+ Misses 32464 32459 -5
- Partials 7778 7780 +2
```
| [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2641?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [.../codehaus/groovy/runtime/DefaultGroovyMethods.java](https://app.codecov.io/gh/apache/groovy/pull/2641?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fruntime%2FDefaultGroovyMethods.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3J1bnRpbWUvRGVmYXVsdEdyb292eU1ldGhvZHMuamF2YQ==) | `74.9933% <100.0000%> (+0.0401%)` | :arrow_up: |
... and [7 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2641/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org