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:
Protobuf Team Bot 2026-08-24 17:01:40 -07:00 committed by Copybara-Service
parent 44baf91cc1
commit 7f86060aae

View file

@ -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());
}
/**