EgorBaranovEnjoysTyping commented on code in PR #13262:
URL: https://github.com/apache/ignite/pull/13262#discussion_r3481272873
##########
modules/commons/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java:
##########
@@ -1994,87 +1497,13 @@ public static <T> String joinToString(
return buf.toString();
}
- /**
- * Checks that object is already saved.
- * In positive case this method inserts hash to the saved object entry (if
needed) and name@hash for current entry.
- * Further toString operations are not needed for current object.
- *
- * @param buf String builder buffer.
- * @param obj Object.
- * @param cls Class.
- * @param svdObjs Map with saved objects to handle recursion.
- * @return {@code True} if object is already saved and name@hash was added
to buffer.
- * {@code False} if it wasn't saved previously and it should be saved.
- */
- private static boolean handleRecursion(
- SBLimitedLength buf,
- Object obj,
- @NotNull Class cls,
- IdentityHashMap<Object, EntryReference> svdObjs
- ) {
- EntryReference ref = svdObjs.get(obj);
-
- if (ref == null)
- return false;
-
- int pos = ref.pos;
-
- String name = cls.getSimpleName();
- String hash = identity(obj);
- String savedName = name + hash;
- String charsAtPos = buf.impl().substring(pos, pos +
savedName.length());
-
- if (!buf.isOverflowed() && !savedName.equals(charsAtPos)) {
- if (charsAtPos.startsWith(cls.getSimpleName())) {
- buf.i(pos + name.length(), hash);
-
- incValues(svdObjs, obj, hash.length());
- }
- else
- ref.hashNeeded = true;
- }
-
- buf.a(savedName);
-
- return true;
- }
-
- /**
- * Increment positions of already presented objects afterward given object.
- *
- * @param svdObjs Map with objects already presented in the buffer.
- * @param obj Object.
- * @param hashLen Length of the object's hash.
- */
- private static void incValues(IdentityHashMap<Object, EntryReference>
svdObjs, Object obj, int hashLen) {
- int baseline = svdObjs.get(obj).pos;
-
- for (IdentityHashMap.Entry<Object, EntryReference> entry :
svdObjs.entrySet()) {
- EntryReference ref = entry.getValue();
-
- int pos = ref.pos;
-
- if (pos > baseline)
- ref.pos = pos + hashLen;
- }
- }
-
- /**
- *
- */
- private static class EntryReference {
- /** Position. */
- int pos;
-
- /** First object entry needs hash to be written. */
- boolean hashNeeded;
-
- /**
- * @param pos Position.
- */
- private EntryReference(int pos) {
- this.pos = pos;
- hashNeeded = false;
- }
+ /** */
+ private static <T extends Throwable> String handleThrowable(T throwable) {
+ StringWriter strWriter = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(strWriter);
+ throwable.printStackTrace(printWriter);
+ printWriter.flush();
+ printWriter.close();
+ return strWriter.toString();
}
Review Comment:
Unfortunately it's the only way to show exception if it happens
--
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]