mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Avoid unchecked cast warnings in TextFormat.parse
Use Class.cast instead of unchecked casts to eliminate @SuppressWarnings("unchecked") in TextFormat.parse overloads.
Shouldn't be a performance problem - this is only available in full runtime (not android) where hotspot has a class.cast intrinsic (and text proto parsing is relatively slow anyway, this won't be the bottleneck).
PiperOrigin-RevId: 970171466
This commit is contained in:
parent
44baf91cc1
commit
7f86060aae
1 changed files with 2 additions and 6 deletions
|
|
@ -1816,9 +1816,7 @@ public final class TextFormat {
|
|||
throws ParseException {
|
||||
Message.Builder builder = Internal.getDefaultInstance(protoClass).newBuilderForType();
|
||||
merge(input, builder);
|
||||
@SuppressWarnings("unchecked")
|
||||
T output = (T) builder.build();
|
||||
return output;
|
||||
return protoClass.cast(builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1858,9 +1856,7 @@ public final class TextFormat {
|
|||
throws ParseException {
|
||||
Message.Builder builder = Internal.getDefaultInstance(protoClass).newBuilderForType();
|
||||
merge(input, extensionRegistry, builder);
|
||||
@SuppressWarnings("unchecked")
|
||||
T output = (T) builder.build();
|
||||
return output;
|
||||
return protoClass.cast(builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue