Fix #1175: Change IndexInputStream to throw NotSupportedException for…#1231
Fix #1175: Change IndexInputStream to throw NotSupportedException for…#1231NightOwl888 merged 1 commit intoapache:masterfrom
Conversation
…on for writable members Changed Flush(), SetLength(), and Write() methods to throw NotSupportedException instead of IllegalStateException/InvalidCastException to be consistent with .NET conventions for read-only streams. Added unit tests to verify the correct exception types are thrown.
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #1175 by updating IndexInputStream to throw NotSupportedException instead of IllegalStateException or InvalidCastException for unsupported write operations on the read-only stream, aligning with .NET Stream conventions.
- Changed exception types in
Flush(),SetLength(), andWrite()methods from Lucene-specific exceptions to .NET's standardNotSupportedException - Added comprehensive unit tests to verify correct exception behavior
- Removed TODO comments that questioned whether to use
NotSupportedException
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Lucene.Net.Replicator/IndexInputInputStream.cs | Updated three methods (Flush, SetLength, Write) to throw NotSupportedException instead of IllegalStateException/InvalidCastException, conforming to .NET Stream conventions for read-only streams |
| src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs | Added three unit tests to verify that Flush, SetLength, and Write methods correctly throw NotSupportedException |
The changes in this PR are well-structured and appropriate. The use of NotSupportedException is the correct .NET convention for Stream methods that are not supported (as indicated by CanWrite => false). The tests properly validate the expected behavior, and the implementation is clean and consistent.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary of the changes (Less than 80 chars)
Fixes #1175
Description
Change IndexInputStream to throw NotSupportedException for writable members
Changed Flush(), SetLength(), and Write() methods to throw NotSupportedException instead of IllegalStateException/InvalidCastException to be consistent with .NET conventions for read-only streams.
Added unit tests to verify the correct exception types are thrown.