-
Couldn't load subscription status.
- Fork 5.2k
Fix RangeAttribute to catch OverflowException instead of throwing #121029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Added catch for OverflowException in RangeAttribute.IsValid() - Added catch for OverflowException in Emitter.cs source generator - Updated and added tests to verify overflow values return false - Changed test expectation from throwing to returning false Co-authored-by: stephentoub <[email protected]>
|
Tagging subscribers to this area: @dotnet/area-system-componentmodel-dataannotations |
Updated all 8 baseline test files to include OverflowException in the catch clause, matching the generator changes made in Emitter.cs Co-authored-by: stephentoub <[email protected]>
|
@copilot, this is failing tests: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where RangeAttribute.IsValid() throws an uncaught OverflowException instead of returning false when validating values that exceed the bounds of the operand type (e.g., a long value exceeding int.MaxValue).
Key changes:
- Added
OverflowExceptionto the exception handling inRangeAttribute.IsValid() - Updated source generator to include
OverflowExceptionin generated validation code - Modified tests to expect
falsereturn value instead of thrown exceptions for overflow scenarios
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| RangeAttribute.cs | Added catch block for OverflowException to return false instead of propagating the exception |
| Emitter.cs | Updated source generator exception filters to include OverflowException in two locations |
| RangeAttributeTests.cs | Changed test expectations from throwing exception to returning false, added new test cases for overflow values |
| OptionsExtendingSystemClassTest.netfx.g.cs | Updated baseline with new exception filter |
| OptionsExtendingSystemClassTest.netcore.g.cs | Updated baseline with new exception filter |
| GeneratedAttributesTest.netfx.lang11.g.cs | Updated baseline with new exception filter |
| GeneratedAttributesTest.netfx.lang10.g.cs | Updated baseline with new exception filter |
| GeneratedAttributesTest.netcore.lang11.g.cs | Updated baseline with new exception filter |
| GeneratedAttributesTest.netcore.lang10.g.cs | Updated baseline with new exception filter |
| EmitterWithCustomValidator.netfx.g.cs | Updated baseline with new exception filter |
| EmitterWithCustomValidator.netcore.g.cs | Updated baseline with new exception filter |
Updated the two additional baseline files (NetCoreApp and NetFX Validators.g.cs) that were missed in the previous commit to include OverflowException in the catch clause. Co-authored-by: stephentoub <[email protected]>
... Fixed in commit 23b1940. Updated the two missing baseline files (NetCoreApp/Validators.g.cs and NetFX/Validators.g.cs) to include OverflowException. All tests now pass. |
|
/ba-g debug and AOT legs timed out, unrelated to the change. |
Fix RangeAttribute to handle OverflowException
Summary
Fixed RangeAttribute.IsValid() to catch OverflowException and return false instead of throwing an uncaught exception when values exceed the bounds of the operand type.
Changes Made
Issue Resolution
The issue reported that passing values like 2147483648L (exceeds int.MaxValue) to RangeAttribute(-50, 50) threw OverflowException instead of returning false. This fix ensures IsValid() properly catches OverflowException during type conversion and returns false as expected.
Files Changed
RangeAttribute.cs- Added OverflowException catch blockEmitter.cs- Added OverflowException to catch filter (2 locations)RangeAttributeTests.cs- Updated test expectations and added overflow test casesOriginal prompt
Fixes #115982
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.