api: Early-detect null bytes from Metadata.Marshaller

See #9706
This commit is contained in:
Eric Anderson 2023-01-05 17:36:24 -08:00 committed by GitHub
parent d17a2db4bd
commit cc5378453f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -873,7 +873,7 @@ public final class Metadata {
@Override @Override
byte[] toBytes(T value) { byte[] toBytes(T value) {
return marshaller.toBytes(value); return Preconditions.checkNotNull(marshaller.toBytes(value), "null marshaller.toBytes()");
} }
@Override @Override
@ -901,7 +901,7 @@ public final class Metadata {
@Override @Override
byte[] toBytes(T value) { byte[] toBytes(T value) {
return streamToBytes(marshaller.toStream(value)); return streamToBytes(checkNotNull(marshaller.toStream(value), "null marshaller.toStream()"));
} }
@Override @Override
@ -932,7 +932,7 @@ public final class Metadata {
} }
InputStream toStream() { InputStream toStream() {
return marshaller.toStream(value); return checkNotNull(marshaller.toStream(value), "null marshaller.toStream()");
} }
byte[] toBytes() { byte[] toBytes() {
@ -979,7 +979,9 @@ public final class Metadata {
@Override @Override
byte[] toBytes(T value) { byte[] toBytes(T value) {
return marshaller.toAsciiString(value).getBytes(US_ASCII); String encoded = Preconditions.checkNotNull(
marshaller.toAsciiString(value), "null marshaller.toAsciiString()");
return encoded.getBytes(US_ASCII);
} }
@Override @Override
@ -1004,7 +1006,8 @@ public final class Metadata {
@Override @Override
byte[] toBytes(T value) { byte[] toBytes(T value) {
return marshaller.toAsciiString(value); return Preconditions.checkNotNull(
marshaller.toAsciiString(value), "null marshaller.toAsciiString()");
} }
@Override @Override