szetszwo commented on code in PR #9878:
URL: https://github.com/apache/ozone/pull/9878#discussion_r2898982489
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/io/ScmNonShadedGeneratedMessageCodec.java:
##########
@@ -28,25 +27,25 @@
* {@link ScmCodec} implementation for non-shaded
* {@link com.google.protobuf.Message} objects.
*/
-public class ScmNonShadedGeneratedMessageCodec implements ScmCodec<Object> {
+public class ScmNonShadedGeneratedMessageCodec<T extends Message> implements
ScmCodec<T> {
+
+ private final Parser<T> parser;
+
+ public ScmNonShadedGeneratedMessageCodec(Parser<T> parser) {
+ this.parser = parser;
+ }
@Override
- public ByteString serialize(Object object)
- throws InvalidProtocolBufferException {
- return UnsafeByteOperations.unsafeWrap(
- ((Message) object).toByteString().asReadOnlyByteBuffer());
+ public ByteString serialize(T object) throws InvalidProtocolBufferException {
+ return
UnsafeByteOperations.unsafeWrap(object.toByteString().asReadOnlyByteBuffer());
}
@Override
- public Object deserialize(Class<?> type, ByteString value)
- throws InvalidProtocolBufferException {
+ public T deserialize(Class<?> type, ByteString value) throws
InvalidProtocolBufferException {
try {
- return ReflectionUtil.getMethod(type, "parseFrom", byte[].class)
- .invoke(null, (Object) value.toByteArray());
- } catch (NoSuchMethodException | IllegalAccessException
- | InvocationTargetException ex) {
- ex.printStackTrace();
- throw new InvalidProtocolBufferException("Message cannot be decoded: " +
ex.getMessage());
+ return parser.parseFrom(value.toByteArray());
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw new IllegalArgumentException("Message cannot be decoded", e);
Review Comment:
We should throw
`org.apache.ratis.thirdparty.com.google.protobuf.InvalidProtocolBufferException`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]