-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
ByteString.Output is missing an override for write(byte[]) that does not throw IOException #19741
Comments
…IOException Fixes #19741 PiperOrigin-RevId: 707957097
Unfortunately while this makes a lot of sense, this would break anyone currently using But please reopen if there's something I've failed to consider here that would make this more doable!
|
Agree, it's not appropriate for a minor release for that reason, but perhaps would be for the next major release. Even though a new error would occur, it would only do so in situations where a code clean up is possible, which hopefully people would appreciate.
What about a non-overriding version of the method then? E.g.: diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java
index 1903a4deb..d8d6ebd2b 100644
--- a/java/core/src/main/java/com/google/protobuf/ByteString.java
+++ b/java/core/src/main/java/com/google/protobuf/ByteString.java
@@ -1088,6 +1088,15 @@ public abstract class ByteString implements Iterable<Byte>, Serializable {
buffer[bufferPos++] = (byte) b;
}
+ /**
+ * Write the entire contents of the given array.
+ *
+ * @param b byte data to write
+ */
+ public void writeArray(byte[] b) {
+ this.write(b, 0, b.length);
+ }
+
@Override
public synchronized void write(byte[] b, int offset, int length) {
if (length <= buffer.length - bufferPos) { FYI I'm not permitted to reopen this. Thanks. |
Our next breaking change in Java will likely be in ~2026 Q1 which is the earliest we could probably consider this. Unfortunately this would require some effort to clean-up since I'm not sure there's a great way to address this. Simply doing this in a breaking change would likely require users with many call-sites (incl. google) to update atomically. I don't think we'd want to introduce a second API, unless it were temporary with a plan to delete it. To do this properly, I think we would need to do something like:
This is a lot of disruption with not a ton of value for existing users unfortunately. :( |
OK, thanks. I was hoping I'll look elsewhere. |
What language does this apply to?
Java
Describe the problem you are trying to solve.
The
ByteString.Output
class extendsOutputStream
. Because it actually writes into memory, not into some I/O stream, thewrite(int b)
andwrite(byte[] a, int off, int len)
methods are declared to not throwIOException
- which is a great feature!However, this feature has an omission, which is that the
write(byte[] a)
method is not included in this feature.Describe the solution you'd like
Simply have
ByteString.Output
declare an override forwrite(byte[] a)
that does not throwIOException
:Describe alternatives you've considered
Uglying up my code by catching and ignoring an
IOException
that will never be thrown.The text was updated successfully, but these errors were encountered: