[ https://issues.apache.org/jira/browse/GIRAPH-1163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16201075#comment-16201075 ]
ASF GitHub Bot commented on GIRAPH-1163: ---------------------------------------- Github user yukselakinci commented on a diff in the pull request: https://github.com/apache/giraph/pull/52#discussion_r144152025 --- Diff: giraph-core/src/main/java/org/apache/giraph/writable/kryo/KryoWritableWrapper.java --- @@ -120,4 +126,50 @@ public static Writable wrapIfNeeded(Object object) { public static <T> T wrapAndCopy(T object) { return WritableUtils.createCopy(new KryoWritableWrapper<>(object)).get(); } + + /** + * Try converting the object to byte array. + * @param object Object + * @param <T> Type + * @return byte array + */ + public static <T> byte [] tryConvertToByteArray(T object) { + byte [] arr = null; + try { + KryoWritableWrapper<T> wrapper = + new KryoWritableWrapper<>(object); + arr = WritableUtils.toByteArrayUnsafe(wrapper); + // Checkstyle exception due to unsafe conversion + // CHECKSTYLE: stop IllegalCatch + } catch (Exception e) { --- End diff -- The reason I added was because, the caller could chose any T values, and if the object that was initially converted to byte array is not related to T, then it can throw. But more importantly, there are other callers of this functionality and I don't want to have repeating try-catch blocks. Another option is to add a new utility class that would include the try-catch. Let me know if you think that would be better. > Changes to support sending exceptions over thrift calls. > -------------------------------------------------------- > > Key: GIRAPH-1163 > URL: https://issues.apache.org/jira/browse/GIRAPH-1163 > Project: Giraph > Issue Type: Bug > Reporter: Yuksel Akinci > -- This message was sent by Atlassian JIRA (v6.4.14#64029)