You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ni...@apache.org on 2018/11/24 06:38:39 UTC
[1/3] ignite git commit: Revert "IGNITE-8493 GridToStringBuilder
arrayToString refactoring. - Fixes #4501."
Repository: ignite
Updated Branches:
refs/heads/ignite-2.7 c670b012c -> 307ac58d1
Revert "IGNITE-8493 GridToStringBuilder arrayToString refactoring. - Fixes #4501."
This reverts commit dd8c933fd44e4ad9b315daccce8e2327606867b0.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e6b42abb
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e6b42abb
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e6b42abb
Branch: refs/heads/ignite-2.7
Commit: e6b42abb81c22bd119a9233023be6be66b2aad09
Parents: c670b01
Author: Nikolay Izhikov <ni...@apache.org>
Authored: Fri Nov 23 22:51:08 2018 +0300
Committer: Nikolay Izhikov <ni...@apache.org>
Committed: Fri Nov 23 22:51:08 2018 +0300
----------------------------------------------------------------------
.../util/tostring/GridToStringBuilder.java | 129 +++++++++++--------
.../tostring/GridToStringBuilderSelfTest.java | 97 +++++---------
...niteHadoopFileSystemClientBasedOpenTest.java | 2 +-
3 files changed, 112 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e6b42abb/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
index 329682f..67b9af1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
@@ -21,7 +21,6 @@ import java.io.Externalizable;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
-import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
@@ -854,7 +853,7 @@ public class GridToStringBuilder {
*/
private static void addArray(SBLimitedLength buf, Class arrType, Object obj) {
if (arrType.getComponentType().isPrimitive()) {
- buf.a(arrayToString(obj));
+ buf.a(arrayToString(arrType, obj));
return;
}
@@ -1076,40 +1075,95 @@ public class GridToStringBuilder {
}
/**
- * Returns limited string representation of array.
- *
- * @param arr Array object. Each value is automatically wrapped if it has a primitive type.
+ * @param arrType Type of the array.
+ * @param arr Array object.
* @return String representation of an array.
*/
- public static String arrayToString(Object arr) {
+ @SuppressWarnings({"ConstantConditions", "unchecked"})
+ public static <T> String arrayToString(Class arrType, Object arr) {
if (arr == null)
return "null";
String res;
+ int more = 0;
- int arrLen;
-
- if (arr instanceof Object[]) {
+ if (arrType.equals(byte[].class)) {
+ byte[] byteArr = (byte[])arr;
+ if (byteArr.length > COLLECTION_LIMIT) {
+ more = byteArr.length - COLLECTION_LIMIT;
+ byteArr = Arrays.copyOf(byteArr, COLLECTION_LIMIT);
+ }
+ res = Arrays.toString(byteArr);
+ }
+ else if (arrType.equals(boolean[].class)) {
+ boolean[] boolArr = (boolean[])arr;
+ if (boolArr.length > COLLECTION_LIMIT) {
+ more = boolArr.length - COLLECTION_LIMIT;
+ boolArr = Arrays.copyOf(boolArr, COLLECTION_LIMIT);
+ }
+ res = Arrays.toString(boolArr);
+ }
+ else if (arrType.equals(short[].class)) {
+ short[] shortArr = (short[])arr;
+ if (shortArr.length > COLLECTION_LIMIT) {
+ more = shortArr.length - COLLECTION_LIMIT;
+ shortArr = Arrays.copyOf(shortArr, COLLECTION_LIMIT);
+ }
+ res = Arrays.toString(shortArr);
+ }
+ else if (arrType.equals(int[].class)) {
+ int[] intArr = (int[])arr;
+ if (intArr.length > COLLECTION_LIMIT) {
+ more = intArr.length - COLLECTION_LIMIT;
+ intArr = Arrays.copyOf(intArr, COLLECTION_LIMIT);
+ }
+ res = Arrays.toString(intArr);
+ }
+ else if (arrType.equals(long[].class)) {
+ long[] longArr = (long[])arr;
+ if (longArr.length > COLLECTION_LIMIT) {
+ more = longArr.length - COLLECTION_LIMIT;
+ longArr = Arrays.copyOf(longArr, COLLECTION_LIMIT);
+ }
+ res = Arrays.toString(longArr);
+ }
+ else if (arrType.equals(float[].class)) {
+ float[] floatArr = (float[])arr;
+ if (floatArr.length > COLLECTION_LIMIT) {
+ more = floatArr.length - COLLECTION_LIMIT;
+ floatArr = Arrays.copyOf(floatArr, COLLECTION_LIMIT);
+ }
+ res = Arrays.toString(floatArr);
+ }
+ else if (arrType.equals(double[].class)) {
+ double[] doubleArr = (double[])arr;
+ if (doubleArr.length > COLLECTION_LIMIT) {
+ more = doubleArr.length - COLLECTION_LIMIT;
+ doubleArr = Arrays.copyOf(doubleArr, COLLECTION_LIMIT);
+ }
+ res = Arrays.toString(doubleArr);
+ }
+ else if (arrType.equals(char[].class)) {
+ char[] charArr = (char[])arr;
+ if (charArr.length > COLLECTION_LIMIT) {
+ more = charArr.length - COLLECTION_LIMIT;
+ charArr = Arrays.copyOf(charArr, COLLECTION_LIMIT);
+ }
+ res = Arrays.toString(charArr);
+ }
+ else {
Object[] objArr = (Object[])arr;
-
- arrLen = objArr.length;
-
- if (arrLen > COLLECTION_LIMIT)
+ if (objArr.length > COLLECTION_LIMIT) {
+ more = objArr.length - COLLECTION_LIMIT;
objArr = Arrays.copyOf(objArr, COLLECTION_LIMIT);
-
+ }
res = Arrays.toString(objArr);
- } else {
- res = toStringWithLimit(arr, COLLECTION_LIMIT);
-
- arrLen = Array.getLength(arr);
}
-
- if (arrLen > COLLECTION_LIMIT) {
+ if (more > 0) {
StringBuilder resSB = new StringBuilder(res);
resSB.deleteCharAt(resSB.length() - 1);
-
- resSB.append("... and ").append(arrLen - COLLECTION_LIMIT).append(" more]");
+ resSB.append("... and ").append(more).append(" more]");
res = resSB.toString();
}
@@ -1118,37 +1172,6 @@ public class GridToStringBuilder {
}
/**
- * Returns limited string representation of array.
- *
- * @param arr Input array. Each value is automatically wrapped if it has a primitive type.
- * @param limit max array items to string limit.
- * @return String representation of an array.
- */
- private static String toStringWithLimit(Object arr, int limit) {
- int arrIdxMax = Array.getLength(arr) - 1;
-
- if (arrIdxMax == -1)
- return "[]";
-
- int idxMax = Math.min(arrIdxMax, limit);
-
- StringBuilder b = new StringBuilder();
-
- b.append('[');
-
- for (int i = 0; i <= idxMax; ++i) {
- b.append(Array.get(arr, i));
-
- if (i == idxMax)
- return b.append(']').toString();
-
- b.append(", ");
- }
-
- return b.toString();
- }
-
- /**
* Produces uniformed output of string with context properties
*
* @param str Output prefix or {@code null} if empty.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e6b42abb/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
index d249914..9a9e67e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
@@ -304,8 +304,8 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
* @param limit Array limit.
*/
private void checkArrayOverflow(Object[] arrOf, Object[] arr, int limit) {
- String arrStr = GridToStringBuilder.arrayToString(arr);
- String arrOfStr = GridToStringBuilder.arrayToString(arrOf);
+ String arrStr = GridToStringBuilder.arrayToString(arr.getClass(), arr);
+ String arrOfStr = GridToStringBuilder.arrayToString(arrOf.getClass(), arrOf);
// Simulate overflow
StringBuilder resultSB = new StringBuilder(arrStr);
@@ -332,97 +332,75 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
for (Object val : vals)
testArr(val, limit);
- int[] intArr1 = new int[0];
-
- assertEquals("[]", GridToStringBuilder.arrayToString(intArr1));
- assertEquals("null", GridToStringBuilder.arrayToString(null));
-
- int[] intArr2 = {1, 2, 3};
-
- assertEquals("[1, 2, 3]", GridToStringBuilder.arrayToString(intArr2));
-
- Object[] intArr3 = {2, 3, 4};
-
- assertEquals("[2, 3, 4]", GridToStringBuilder.arrayToString(intArr3));
-
byte[] byteArr = new byte[1];
-
byteArr[0] = 1;
- assertEquals(Arrays.toString(byteArr), GridToStringBuilder.arrayToString(byteArr));
+ assertEquals(Arrays.toString(byteArr), GridToStringBuilder.arrayToString(byteArr.getClass(), byteArr));
byteArr = Arrays.copyOf(byteArr, 101);
assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
- GridToStringBuilder.arrayToString(byteArr).contains("... and 1 more"));
+ GridToStringBuilder.arrayToString(byteArr.getClass(), byteArr).contains("... and 1 more"));
boolean[] boolArr = new boolean[1];
-
boolArr[0] = true;
- assertEquals(Arrays.toString(boolArr), GridToStringBuilder.arrayToString(boolArr));
+ assertEquals(Arrays.toString(boolArr), GridToStringBuilder.arrayToString(boolArr.getClass(), boolArr));
boolArr = Arrays.copyOf(boolArr, 101);
assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
- GridToStringBuilder.arrayToString(boolArr).contains("... and 1 more"));
+ GridToStringBuilder.arrayToString(boolArr.getClass(), boolArr).contains("... and 1 more"));
short[] shortArr = new short[1];
-
shortArr[0] = 100;
- assertEquals(Arrays.toString(shortArr), GridToStringBuilder.arrayToString(shortArr));
+ assertEquals(Arrays.toString(shortArr), GridToStringBuilder.arrayToString(shortArr.getClass(), shortArr));
shortArr = Arrays.copyOf(shortArr, 101);
assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
- GridToStringBuilder.arrayToString(shortArr).contains("... and 1 more"));
+ GridToStringBuilder.arrayToString(shortArr.getClass(), shortArr).contains("... and 1 more"));
int[] intArr = new int[1];
-
intArr[0] = 10000;
- assertEquals(Arrays.toString(intArr), GridToStringBuilder.arrayToString(intArr));
+ assertEquals(Arrays.toString(intArr), GridToStringBuilder.arrayToString(intArr.getClass(), intArr));
intArr = Arrays.copyOf(intArr, 101);
assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
- GridToStringBuilder.arrayToString(intArr).contains("... and 1 more"));
+ GridToStringBuilder.arrayToString(intArr.getClass(), intArr).contains("... and 1 more"));
long[] longArr = new long[1];
-
longArr[0] = 10000000;
- assertEquals(Arrays.toString(longArr), GridToStringBuilder.arrayToString(longArr));
+ assertEquals(Arrays.toString(longArr), GridToStringBuilder.arrayToString(longArr.getClass(), longArr));
longArr = Arrays.copyOf(longArr, 101);
assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
- GridToStringBuilder.arrayToString(longArr).contains("... and 1 more"));
+ GridToStringBuilder.arrayToString(longArr.getClass(), longArr).contains("... and 1 more"));
float[] floatArr = new float[1];
-
floatArr[0] = 1.f;
- assertEquals(Arrays.toString(floatArr), GridToStringBuilder.arrayToString(floatArr));
+ assertEquals(Arrays.toString(floatArr), GridToStringBuilder.arrayToString(floatArr.getClass(), floatArr));
floatArr = Arrays.copyOf(floatArr, 101);
assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
- GridToStringBuilder.arrayToString(floatArr).contains("... and 1 more"));
+ GridToStringBuilder.arrayToString(floatArr.getClass(), floatArr).contains("... and 1 more"));
double[] doubleArr = new double[1];
-
doubleArr[0] = 1.;
- assertEquals(Arrays.toString(doubleArr), GridToStringBuilder.arrayToString(doubleArr));
+ assertEquals(Arrays.toString(doubleArr), GridToStringBuilder.arrayToString(doubleArr.getClass(), doubleArr));
doubleArr = Arrays.copyOf(doubleArr, 101);
assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
- GridToStringBuilder.arrayToString(doubleArr).contains("... and 1 more"));
-
- char[] cArr = new char[1];
+ GridToStringBuilder.arrayToString(doubleArr.getClass(), doubleArr).contains("... and 1 more"));
- cArr[0] = 'a';
- assertEquals(Arrays.toString(cArr), GridToStringBuilder.arrayToString(cArr));
- cArr = Arrays.copyOf(cArr, 101);
+ char[] charArr = new char[1];
+ charArr[0] = 'a';
+ assertEquals(Arrays.toString(charArr), GridToStringBuilder.arrayToString(charArr.getClass(), charArr));
+ charArr = Arrays.copyOf(charArr, 101);
assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
- GridToStringBuilder.arrayToString(cArr).contains("... and 1 more"));
+ GridToStringBuilder.arrayToString(charArr.getClass(), charArr).contains("... and 1 more"));
Map<String, String> strMap = new TreeMap<>();
List<String> strList = new ArrayList<>(limit+1);
- TestClass1 testCls = new TestClass1();
-
- testCls.strMap = strMap;
- testCls.strListIncl = strList;
+ TestClass1 testClass = new TestClass1();
+ testClass.strMap = strMap;
+ testClass.strListIncl = strList;
for (int i = 0; i < limit; i++) {
strMap.put("k" + i, "v");
strList.add("e");
}
- checkColAndMap(testCls);
+ checkColAndMap(testClass);
}
/**
@@ -481,26 +459,21 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
public void testToStringSizeLimits() throws Exception {
int limit = IgniteSystemProperties.getInteger(IGNITE_TO_STRING_MAX_LENGTH, 10_000);
int tailLen = limit / 10 * 2;
-
StringBuilder sb = new StringBuilder(limit + 10);
-
- for (int i = 0; i < limit - 100; i++)
+ for (int i = 0; i < limit - 100; i++) {
sb.append('a');
-
+ }
String actual = GridToStringBuilder.toString(TestClass2.class, new TestClass2(sb.toString()));
- String exp = "TestClass2 [str=" + sb + ", nullArr=null]";
+ String expected = "TestClass2 [str=" + sb.toString() + ", nullArr=null]";
+ assertEquals(expected, actual);
- assertEquals(exp, actual);
-
- for (int i = 0; i < 110; i++)
+ for (int i = 0; i < 110; i++) {
sb.append('b');
-
+ }
actual = GridToStringBuilder.toString(TestClass2.class, new TestClass2(sb.toString()));
- exp = "TestClass2 [str=" + sb + ", nullArr=null]";
-
- assertEquals(exp.substring(0, limit - tailLen), actual.substring(0, limit - tailLen));
- assertEquals(exp.substring(exp.length() - tailLen), actual.substring(actual.length() - tailLen));
-
+ expected = "TestClass2 [str=" + sb.toString() + ", nullArr=null]";
+ assertEquals(expected.substring(0, limit - tailLen), actual.substring(0, limit - tailLen));
+ assertEquals(expected.substring(expected.length() - tailLen), actual.substring(actual.length() - tailLen));
assertTrue(actual.contains("... and"));
assertTrue(actual.contains("skipped ..."));
}
@@ -647,7 +620,7 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
/**
* @param str String.
*/
- TestClass2(String str) {
+ public TestClass2(String str) {
this.str = str;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e6b42abb/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemClientBasedOpenTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemClientBasedOpenTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemClientBasedOpenTest.java
index 932f4d8..289e63d 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemClientBasedOpenTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/impl/igfs/IgniteHadoopFileSystemClientBasedOpenTest.java
@@ -176,7 +176,7 @@ public class IgniteHadoopFileSystemClientBasedOpenTest extends GridCommonAbstrac
*/
private void checkFsOpenWithAllNodesTypes() throws Exception {
for (int i = 0; i < nodesTypes.length; ++i) {
- log.info("Begin test case for nodes: " + S.arrayToString(nodesTypes[i]));
+ log.info("Begin test case for nodes: " + S.arrayToString(NodeType.class, nodesTypes[i]));
startNodes(nodesTypes[i]);
[3/3] ignite git commit: Revert "IGNITE-602 Fixed possible
StackOverflowError in GridToStringBuilder when circular references are
present - Fixes #1558."
Posted by ni...@apache.org.
Revert "IGNITE-602 Fixed possible StackOverflowError in GridToStringBuilder when circular references are present - Fixes #1558."
This reverts commit d67c5bf4c22338695a116e0fbf0a58a4d581af5d.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/307ac58d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/307ac58d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/307ac58d
Branch: refs/heads/ignite-2.7
Commit: 307ac58d1aa1f0145c16affe6de96314b1c8ecef
Parents: 5f968d2
Author: Nikolay Izhikov <ni...@apache.org>
Authored: Fri Nov 23 22:52:12 2018 +0300
Committer: Nikolay Izhikov <ni...@apache.org>
Committed: Fri Nov 23 22:52:12 2018 +0300
----------------------------------------------------------------------
.../util/tostring/GridToStringBuilder.java | 706 ++++++++++---------
.../util/tostring/GridToStringThreadLocal.java | 66 ++
.../internal/util/tostring/SBLimitedLength.java | 20 -
.../tostring/GridToStringBuilderSelfTest.java | 247 +------
4 files changed, 439 insertions(+), 600 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/307ac58d/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
index 86daf7c..77c333d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
@@ -28,16 +28,19 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EventListener;
-import java.util.IdentityHashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.apache.ignite.internal.util.typedef.internal.U;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -47,9 +50,6 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_
/**
* Provides auto-generation framework for {@code toString()} output.
* <p>
- * In case of recursion, repeatable objects will be shown as "ClassName@hash".
- * But fields will be printed only for the first entry to prevent recursion.
- * <p>
* Default exclusion policy (can be overridden with {@link GridToStringInclude}
* annotation):
* <ul>
@@ -84,9 +84,6 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_
*/
public class GridToStringBuilder {
/** */
- private static final Object[] EMPTY_ARRAY = new Object[0];
-
- /** */
private static final Map<String, GridToStringClassDescriptor> classCache = new ConcurrentHashMap<>();
/** {@link IgniteSystemProperties#IGNITE_TO_STRING_INCLUDE_SENSITIVE} */
@@ -97,30 +94,25 @@ public class GridToStringBuilder {
private static final int COLLECTION_LIMIT =
IgniteSystemProperties.getInteger(IGNITE_TO_STRING_COLLECTION_LIMIT, 100);
- /** Every thread has its own string builder. */
- private static ThreadLocal<SBLimitedLength> threadLocSB = new ThreadLocal<SBLimitedLength>() {
- @Override protected SBLimitedLength initialValue() {
- SBLimitedLength sb = new SBLimitedLength(256);
+ /** */
+ private static ThreadLocal<Queue<GridToStringThreadLocal>> threadCache = new ThreadLocal<Queue<GridToStringThreadLocal>>() {
+ @Override protected Queue<GridToStringThreadLocal> initialValue() {
+ Queue<GridToStringThreadLocal> queue = new LinkedList<>();
- sb.initLimit(new SBLengthLimit());
+ queue.offer(new GridToStringThreadLocal());
- return sb;
+ return queue;
}
};
- /**
- * Contains objects currently printing in the string builder.
- * <p>
- * Since {@code toString()} methods can be chain-called from the same thread we
- * have to keep a map of this objects pointed to the position of previous occurrence
- * and remove/add them in each {@code toString()} apply.
- */
- private static ThreadLocal<IdentityHashMap<Object, Integer>> savedObjects = new ThreadLocal<IdentityHashMap<Object, Integer>>() {
- @Override protected IdentityHashMap<Object, Integer> initialValue() {
- return new IdentityHashMap<>();
+ /** */
+ private static ThreadLocal<SBLengthLimit> threadCurLen = new ThreadLocal<SBLengthLimit>() {
+ @Override protected SBLengthLimit initialValue() {
+ return new SBLengthLimit();
}
};
+
/**
* Produces auto-generated output of string presentation for given object and its declaration class.
*
@@ -269,9 +261,18 @@ public class GridToStringBuilder {
assert name3 != null;
assert name4 != null;
- Object[] addNames = new Object[5];
- Object[] addVals = new Object[5];
- boolean[] addSens = new boolean[5];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] addNames = tmp.getAdditionalNames();
+ Object[] addVals = tmp.getAdditionalValues();
+ boolean[] addSens = tmp.getAdditionalSensitives();
addNames[0] = name0;
addVals[0] = val0;
@@ -289,16 +290,20 @@ public class GridToStringBuilder {
addVals[4] = val4;
addSens[4] = sens4;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(cls, sb, obj, addNames, addVals, addSens, 5);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(cls, tmp.getStringBuilder(lenLim), obj, addNames, addVals, addSens, 5);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -344,9 +349,18 @@ public class GridToStringBuilder {
assert name4 != null;
assert name5 != null;
- Object[] addNames = new Object[6];
- Object[] addVals = new Object[6];
- boolean[] addSens = new boolean[6];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] addNames = tmp.getAdditionalNames();
+ Object[] addVals = tmp.getAdditionalValues();
+ boolean[] addSens = tmp.getAdditionalSensitives();
addNames[0] = name0;
addVals[0] = val0;
@@ -367,16 +381,20 @@ public class GridToStringBuilder {
addVals[5] = val5;
addSens[5] = sens5;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(cls, sb, obj, addNames, addVals, addSens, 6);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(cls, tmp.getStringBuilder(lenLim), obj, addNames, addVals, addSens, 6);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -427,9 +445,18 @@ public class GridToStringBuilder {
assert name5 != null;
assert name6 != null;
- Object[] addNames = new Object[7];
- Object[] addVals = new Object[7];
- boolean[] addSens = new boolean[7];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] addNames = tmp.getAdditionalNames();
+ Object[] addVals = tmp.getAdditionalValues();
+ boolean[] addSens = tmp.getAdditionalSensitives();
addNames[0] = name0;
addVals[0] = val0;
@@ -453,16 +480,20 @@ public class GridToStringBuilder {
addVals[6] = val6;
addSens[6] = sens6;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(cls, sb, obj, addNames, addVals, addSens, 7);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(cls, tmp.getStringBuilder(lenLim), obj, addNames, addVals, addSens, 7);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -526,9 +557,18 @@ public class GridToStringBuilder {
assert name2 != null;
assert name3 != null;
- Object[] addNames = new Object[4];
- Object[] addVals = new Object[4];
- boolean[] addSens = new boolean[4];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] addNames = tmp.getAdditionalNames();
+ Object[] addVals = tmp.getAdditionalValues();
+ boolean[] addSens = tmp.getAdditionalSensitives();
addNames[0] = name0;
addVals[0] = val0;
@@ -543,16 +583,20 @@ public class GridToStringBuilder {
addVals[3] = val3;
addSens[3] = sens3;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(cls, sb, obj, addNames, addVals, addSens, 4);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(cls, tmp.getStringBuilder(lenLim), obj, addNames, addVals, addSens, 4);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -608,9 +652,18 @@ public class GridToStringBuilder {
assert name1 != null;
assert name2 != null;
- Object[] addNames = new Object[3];
- Object[] addVals = new Object[3];
- boolean[] addSens = new boolean[3];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] addNames = tmp.getAdditionalNames();
+ Object[] addVals = tmp.getAdditionalValues();
+ boolean[] addSens = tmp.getAdditionalSensitives();
addNames[0] = name0;
addVals[0] = val0;
@@ -622,16 +675,20 @@ public class GridToStringBuilder {
addVals[2] = val2;
addSens[2] = sens2;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(cls, sb, obj, addNames, addVals, addSens, 3);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(cls, tmp.getStringBuilder(lenLim), obj, addNames, addVals, addSens, 3);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -675,9 +732,18 @@ public class GridToStringBuilder {
assert name0 != null;
assert name1 != null;
- Object[] addNames = new Object[2];
- Object[] addVals = new Object[2];
- boolean[] addSens = new boolean[2];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] addNames = tmp.getAdditionalNames();
+ Object[] addVals = tmp.getAdditionalValues();
+ boolean[] addSens = tmp.getAdditionalSensitives();
addNames[0] = name0;
addVals[0] = val0;
@@ -686,16 +752,20 @@ public class GridToStringBuilder {
addVals[1] = val1;
addSens[1] = sens1;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(cls, sb, obj, addNames, addVals, addSens, 2);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(cls, tmp.getStringBuilder(lenLim), obj, addNames, addVals, addSens, 2);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -729,24 +799,37 @@ public class GridToStringBuilder {
assert obj != null;
assert name != null;
- Object[] addNames = new Object[1];
- Object[] addVals = new Object[1];
- boolean[] addSens = new boolean[1];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] addNames = tmp.getAdditionalNames();
+ Object[] addVals = tmp.getAdditionalValues();
+ boolean[] addSens = tmp.getAdditionalSensitives();
addNames[0] = name;
addVals[0] = val;
addSens[0] = sens;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(cls, sb, obj, addNames, addVals, addSens, 1);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(cls, tmp.getStringBuilder(lenLim), obj, addNames, addVals, addSens, 1);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -762,16 +845,30 @@ public class GridToStringBuilder {
assert cls != null;
assert obj != null;
- SBLimitedLength sb = threadLocSB.get();
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
- boolean newStr = sb.length() == 0;
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ SBLengthLimit lenLim = threadCurLen.get();
+
+ boolean newStr = false;
try {
- return toStringImpl(cls, sb, obj, EMPTY_ARRAY, EMPTY_ARRAY, null, 0);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(cls, tmp.getStringBuilder(lenLim), obj, tmp.getAdditionalNames(),
+ tmp.getAdditionalValues(), null, 0);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -789,164 +886,68 @@ public class GridToStringBuilder {
}
/**
- * Print value with length limitation.
- *
+ * Print value with length limitation
* @param buf buffer to print to.
* @param val value to print, can be {@code null}.
*/
private static void toString(SBLimitedLength buf, Object val) {
- toString(buf, null, val);
- }
-
- /**
- * Print value with length limitation.
- *
- * @param buf buffer to print to.
- * @param cls value class.
- * @param val value to print.
- */
- @SuppressWarnings({"unchecked"})
- private static void toString(SBLimitedLength buf, Class<?> cls, Object val) {
- if (val == null) {
+ if (val == null)
buf.a("null");
-
- return;
- }
-
- if (cls == null)
- cls = val.getClass();
-
- if (cls.isPrimitive()) {
- buf.a(val);
-
- return;
- }
-
- IdentityHashMap<Object, Integer> svdObjs = savedObjects.get();
-
- if (handleRecursion(buf, val, svdObjs))
- return;
-
- svdObjs.put(val, buf.length());
-
- try {
- if (cls.isArray())
- addArray(buf, cls, val);
- else if (val instanceof Collection)
- addCollection(buf, (Collection) val);
- else if (val instanceof Map)
- addMap(buf, (Map<?, ?>) val);
- else
- buf.a(val);
- }
- finally {
- svdObjs.remove(val);
- }
- }
-
- /**
- * Writes array to buffer.
- *
- * @param buf String builder buffer.
- * @param arrType Type of the array.
- * @param obj Array object.
- */
- private static void addArray(SBLimitedLength buf, Class arrType, Object obj) {
- if (arrType.getComponentType().isPrimitive()) {
- buf.a(arrayToString(arrType, obj));
-
- return;
- }
-
- Object[] arr = (Object[]) obj;
-
- buf.a(arrType.getSimpleName()).a(" [");
-
- for (int i = 0; i < arr.length; i++) {
- toString(buf, arr[i]);
-
- if (i == COLLECTION_LIMIT - 1 || i == arr.length - 1)
- break;
-
- buf.a(", ");
- }
-
- handleOverflow(buf, arr.length);
-
- buf.a(']');
+ else
+ toString(buf, val.getClass(), val);
}
/**
- * Writes collection to buffer.
- *
- * @param buf String builder buffer.
- * @param col Collection object.
+ * Print value with length limitation
+ * @param buf buffer to print to.
+ * @param valClass value class.
+ * @param val value to print
*/
- private static void addCollection(SBLimitedLength buf, Collection col) {
- buf.a(col.getClass().getSimpleName()).a(" [");
-
- int cnt = 0;
-
- for (Object obj : col) {
- toString(buf, obj);
+ private static void toString(SBLimitedLength buf, Class<?> valClass, Object val) {
+ if (valClass.isArray())
+ buf.a(arrayToString(valClass, val));
+ else {
+ int overflow = 0;
+ char bracket = ' ';
- if (++cnt == COLLECTION_LIMIT || cnt == col.size())
- break;
+ if (val instanceof Collection && ((Collection)val).size() > COLLECTION_LIMIT) {
+ overflow = ((Collection)val).size() - COLLECTION_LIMIT;
+ bracket = ']';
+ val = F.retain((Collection) val, true, COLLECTION_LIMIT);
+ }
+ else if (val instanceof Map && ((Map)val).size() > COLLECTION_LIMIT) {
+ Map<Object, Object> tmp = U.newHashMap(COLLECTION_LIMIT);
- buf.a(", ");
- }
+ overflow = ((Map)val).size() - COLLECTION_LIMIT;
- handleOverflow(buf, col.size());
+ bracket= '}';
- buf.a(']');
- }
-
- /**
- * Writes map to buffer.
- *
- * @param buf String builder buffer.
- * @param map Map object.
- */
- private static <K, V> void addMap(SBLimitedLength buf, Map<K, V> map) {
- buf.a(map.getClass().getSimpleName()).a(" {");
+ int cntr = 0;
- int cnt = 0;
+ for (Object o : ((Map)val).entrySet()) {
+ Map.Entry e = (Map.Entry)o;
- for (Map.Entry<K, V> e : map.entrySet()) {
- toString(buf, e.getKey());
+ tmp.put(e.getKey(), e.getValue());
- buf.a('=');
+ if (++cntr >= COLLECTION_LIMIT)
+ break;
+ }
- toString(buf, e.getValue());
+ val = tmp;
+ }
- if (++cnt == COLLECTION_LIMIT || cnt == map.size())
- break;
+ buf.a(val);
- buf.a(", ");
+ if (overflow > 0) {
+ buf.d(buf.length() - 1);
+ buf.a("... and ").a(overflow).a(" more").a(bracket);
+ }
}
-
- handleOverflow(buf, map.size());
-
- buf.a('}');
- }
-
- /**
- * Writes overflow message to buffer if needed.
- *
- * @param buf String builder buffer.
- * @param size Size to compare with limit.
- */
- private static void handleOverflow(SBLimitedLength buf, int size) {
- int overflow = size - COLLECTION_LIMIT;
-
- if (overflow > 0)
- buf.a("... and ").a(overflow).a(" more");
}
/**
* Creates an uniformed string presentation for the given object.
*
- * @param <T> Type of object.
* @param cls Class of the object.
* @param buf String builder buffer.
* @param obj Object for which to get string presentation.
@@ -955,7 +956,9 @@ public class GridToStringBuilder {
* @param addSens Sensitive flag of values or {@code null} if all values are not sensitive.
* @param addLen How many additional values will be included.
* @return String presentation of the given object.
+ * @param <T> Type of object.
*/
+ @SuppressWarnings({"unchecked"})
private static <T> String toStringImpl(
Class<T> cls,
SBLimitedLength buf,
@@ -972,55 +975,13 @@ public class GridToStringBuilder {
assert addNames.length == addVals.length;
assert addLen <= addNames.length;
- boolean newStr = buf.length() == 0;
-
- IdentityHashMap<Object, Integer> svdObjs = savedObjects.get();
-
- if (newStr)
- svdObjs.put(obj, buf.length());
-
- try {
- String s = toStringImpl0(cls, buf, obj, addNames, addVals, addSens, addLen);
-
- if (newStr)
- return s;
-
- return "";
- }
- finally {
- if (newStr)
- svdObjs.remove(obj);
- }
- }
-
- /**
- * Creates an uniformed string presentation for the given object.
- *
- * @param cls Class of the object.
- * @param buf String builder buffer.
- * @param obj Object for which to get string presentation.
- * @param addNames Names of additional values to be included.
- * @param addVals Additional values to be included.
- * @param addSens Sensitive flag of values or {@code null} if all values are not sensitive.
- * @param addLen How many additional values will be included.
- * @return String presentation of the given object.
- * @param <T> Type of object.
- */
- @SuppressWarnings({"unchecked"})
- private static <T> String toStringImpl0(
- Class<T> cls,
- SBLimitedLength buf,
- T obj,
- Object[] addNames,
- Object[] addVals,
- @Nullable boolean[] addSens,
- int addLen
- ) {
try {
GridToStringClassDescriptor cd = getClassDescriptor(cls);
assert cd != null;
+ buf.setLength(0);
+
buf.a(cd.getSimpleClassName()).a(" [");
boolean first = true;
@@ -1183,24 +1144,37 @@ public class GridToStringBuilder {
public static String toString(String str, String name, @Nullable Object val, boolean sens) {
assert name != null;
- Object[] propNames = new Object[1];
- Object[] propVals = new Object[1];
- boolean[] propSens = new boolean[1];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] propNames = tmp.getAdditionalNames();
+ Object[] propVals = tmp.getAdditionalValues();
+ boolean[] propSens = tmp.getAdditionalSensitives();
propNames[0] = name;
propVals[0] = val;
propSens[0] = sens;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(str, sb, propNames, propVals, propSens, 1);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(str, tmp.getStringBuilder(lenLim), propNames, propVals, propSens, 1);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -1237,9 +1211,18 @@ public class GridToStringBuilder {
assert name0 != null;
assert name1 != null;
- Object[] propNames = new Object[2];
- Object[] propVals = new Object[2];
- boolean[] propSens = new boolean[2];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] propNames = tmp.getAdditionalNames();
+ Object[] propVals = tmp.getAdditionalValues();
+ boolean[] propSens = tmp.getAdditionalSensitives();
propNames[0] = name0;
propVals[0] = val0;
@@ -1248,16 +1231,20 @@ public class GridToStringBuilder {
propVals[1] = val1;
propSens[1] = sens1;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(str, sb, propNames, propVals, propSens, 2);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(str, tmp.getStringBuilder(lenLim), propNames, propVals, propSens, 2);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -1284,9 +1271,18 @@ public class GridToStringBuilder {
assert name1 != null;
assert name2 != null;
- Object[] propNames = new Object[3];
- Object[] propVals = new Object[3];
- boolean[] propSens = new boolean[3];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] propNames = tmp.getAdditionalNames();
+ Object[] propVals = tmp.getAdditionalValues();
+ boolean[] propSens = tmp.getAdditionalSensitives();
propNames[0] = name0;
propVals[0] = val0;
@@ -1298,16 +1294,20 @@ public class GridToStringBuilder {
propVals[2] = val2;
propSens[2] = sens2;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(str, sb, propNames, propVals, propSens, 3);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(str, tmp.getStringBuilder(lenLim), propNames, propVals, propSens, 3);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -1339,9 +1339,18 @@ public class GridToStringBuilder {
assert name2 != null;
assert name3 != null;
- Object[] propNames = new Object[4];
- Object[] propVals = new Object[4];
- boolean[] propSens = new boolean[4];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] propNames = tmp.getAdditionalNames();
+ Object[] propVals = tmp.getAdditionalValues();
+ boolean[] propSens = tmp.getAdditionalSensitives();
propNames[0] = name0;
propVals[0] = val0;
@@ -1356,16 +1365,20 @@ public class GridToStringBuilder {
propVals[3] = val3;
propSens[3] = sens3;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(str, sb, propNames, propVals, propSens, 4);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(str, tmp.getStringBuilder(lenLim), propNames, propVals, propSens, 4);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -1402,9 +1415,18 @@ public class GridToStringBuilder {
assert name3 != null;
assert name4 != null;
- Object[] propNames = new Object[5];
- Object[] propVals = new Object[5];
- boolean[] propSens = new boolean[5];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] propNames = tmp.getAdditionalNames();
+ Object[] propVals = tmp.getAdditionalValues();
+ boolean[] propSens = tmp.getAdditionalSensitives();
propNames[0] = name0;
propVals[0] = val0;
@@ -1422,16 +1444,20 @@ public class GridToStringBuilder {
propVals[4] = val4;
propSens[4] = sens4;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(str, sb, propNames, propVals, propSens, 5);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(str, tmp.getStringBuilder(lenLim), propNames, propVals, propSens, 5);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -1473,9 +1499,18 @@ public class GridToStringBuilder {
assert name4 != null;
assert name5 != null;
- Object[] propNames = new Object[6];
- Object[] propVals = new Object[6];
- boolean[] propSens = new boolean[6];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] propNames = tmp.getAdditionalNames();
+ Object[] propVals = tmp.getAdditionalValues();
+ boolean[] propSens = tmp.getAdditionalSensitives();
propNames[0] = name0;
propVals[0] = val0;
@@ -1496,16 +1531,20 @@ public class GridToStringBuilder {
propVals[5] = val5;
propSens[5] = sens5;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(str, sb, propNames, propVals, propSens, 6);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(str, tmp.getStringBuilder(lenLim), propNames, propVals, propSens, 6);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -1552,9 +1591,18 @@ public class GridToStringBuilder {
assert name5 != null;
assert name6 != null;
- Object[] propNames = new Object[7];
- Object[] propVals = new Object[7];
- boolean[] propSens = new boolean[7];
+ Queue<GridToStringThreadLocal> queue = threadCache.get();
+
+ assert queue != null;
+
+ // Since string() methods can be chain-called from the same thread we
+ // have to keep a list of thread-local objects and remove/add them
+ // in each string() apply.
+ GridToStringThreadLocal tmp = queue.isEmpty() ? new GridToStringThreadLocal() : queue.remove();
+
+ Object[] propNames = tmp.getAdditionalNames();
+ Object[] propVals = tmp.getAdditionalValues();
+ boolean[] propSens = tmp.getAdditionalSensitives();
propNames[0] = name0;
propVals[0] = val0;
@@ -1578,16 +1626,20 @@ public class GridToStringBuilder {
propVals[6] = val6;
propSens[6] = sens6;
- SBLimitedLength sb = threadLocSB.get();
+ SBLengthLimit lenLim = threadCurLen.get();
- boolean newStr = sb.length() == 0;
+ boolean newStr = false;
try {
- return toStringImpl(str, sb, propNames, propVals, propSens, 7);
+ newStr = lenLim.length() == 0;
+
+ return toStringImpl(str, tmp.getStringBuilder(lenLim), propNames, propVals, propSens, 7);
}
finally {
+ queue.offer(tmp);
+
if (newStr)
- sb.reset();
+ lenLim.reset();
}
}
@@ -1789,54 +1841,4 @@ public class GridToStringBuilder {
return sb.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 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, IdentityHashMap<Object, Integer> svdObjs) {
- Integer pos = svdObjs.get(obj);
-
- if (pos == null)
- return false;
-
- String name = obj.getClass().getSimpleName();
- String hash = '@' + Integer.toHexString(System.identityHashCode(obj));
- String savedName = name + hash;
-
- if (!buf.isOverflowed() && buf.impl().indexOf(savedName, pos) != pos) {
- buf.i(pos + name.length(), hash);
-
- incValues(svdObjs, obj, hash.length());
- }
-
- 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, Integer> svdObjs, Object obj, int hashLen) {
- Integer baseline = svdObjs.get(obj);
-
- for (IdentityHashMap.Entry<Object, Integer> entry : svdObjs.entrySet()) {
- Integer pos = entry.getValue();
-
- if (pos > baseline)
- entry.setValue(pos + hashLen);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/307ac58d/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringThreadLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringThreadLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringThreadLocal.java
new file mode 100644
index 0000000..2f62727
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringThreadLocal.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util.tostring;
+
+/**
+ * Helper wrapper containing StringBuilder and additional values. Stored as a thread-local variable.
+ */
+class GridToStringThreadLocal {
+ /** */
+ private SBLimitedLength sb = new SBLimitedLength(256);
+
+ /** */
+ private Object[] addNames = new Object[7];
+
+ /** */
+ private Object[] addVals = new Object[7];
+
+ /** */
+ private boolean[] addSens = new boolean[7];
+
+ /**
+ * @param len Length limit.
+ * @return String builder.
+ */
+ SBLimitedLength getStringBuilder(SBLengthLimit len) {
+ sb.initLimit(len);
+
+ return sb;
+ }
+
+ /**
+ * @return Additional names.
+ */
+ Object[] getAdditionalNames() {
+ return addNames;
+ }
+
+ /**
+ * @return Additional values.
+ */
+ Object[] getAdditionalValues() {
+ return addVals;
+ }
+
+ /**
+ * @return Additional values.
+ */
+ boolean[] getAdditionalSensitives() {
+ return addSens;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/307ac58d/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java
index b524b3d..c47cf40 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/SBLimitedLength.java
@@ -51,19 +51,6 @@ public class SBLimitedLength extends GridStringBuilder {
}
/**
- * Resets buffer.
- */
- public void reset() {
- super.setLength(0);
-
- lenLimit.reset();
-
- if (tail != null)
- tail.reset();
- }
-
-
- /**
* @return tail string builder.
*/
public CircularStringBuilder getTail() {
@@ -305,11 +292,4 @@ public class SBLimitedLength extends GridStringBuilder {
return res.toString();
}
}
-
- /**
- * @return {@code True} - if buffer limit is reached.
- */
- public boolean isOverflowed() {
- return lenLimit.overflowed(this);
- }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/307ac58d/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
index eff3349..4ac05fb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
@@ -20,25 +20,19 @@ package org.apache.ignite.internal.util.tostring;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.locks.ReadWriteLock;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteSystemProperties;
-import org.apache.ignite.internal.IgniteInternalFuture;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_COLLECTION_LIMIT;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_MAX_LENGTH;
import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.apache.ignite.testframework.junits.common.GridCommonTest;
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_COLLECTION_LIMIT;
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_MAX_LENGTH;
-
/**
* Tests for {@link GridToStringBuilder}.
*/
@@ -78,164 +72,32 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
/**
* @throws Exception If failed.
*/
- public void testToStringCheckSimpleListRecursionPrevention() throws Exception {
+ public void testToStringCheckSimpleRecursionPrevention() throws Exception {
ArrayList<Object> list1 = new ArrayList<>();
ArrayList<Object> list2 = new ArrayList<>();
list2.add(list1);
list1.add(list2);
- info(GridToStringBuilder.toString(ArrayList.class, list1));
- info(GridToStringBuilder.toString(ArrayList.class, list2));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testToStringCheckSimpleMapRecursionPrevention() throws Exception {
- HashMap<Object, Object> map1 = new HashMap<>();
- HashMap<Object, Object> map2 = new HashMap<>();
-
- map1.put("2", map2);
- map2.put("1", map1);
- info(GridToStringBuilder.toString(HashMap.class, map1));
- info(GridToStringBuilder.toString(HashMap.class, map2));
+ GridToStringBuilder.toString(ArrayList.class, list1);
+ GridToStringBuilder.toString(ArrayList.class, list2);
}
/**
* @throws Exception If failed.
*/
- public void testToStringCheckListAdvancedRecursionPrevention() throws Exception {
+ public void testToStringCheckAdvancedRecursionPrevention() throws Exception {
+ fail("https://issues.apache.org/jira/browse/IGNITE-602");
+
ArrayList<Object> list1 = new ArrayList<>();
ArrayList<Object> list2 = new ArrayList<>();
list2.add(list1);
list1.add(list2);
- info(GridToStringBuilder.toString(ArrayList.class, list1, "name", list2));
- info(GridToStringBuilder.toString(ArrayList.class, list2, "name", list1));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testToStringCheckMapAdvancedRecursionPrevention() throws Exception {
- HashMap<Object, Object> map1 = new HashMap<>();
- HashMap<Object, Object> map2 = new HashMap<>();
-
- map1.put("2", map2);
- map2.put("1", map1);
-
- info(GridToStringBuilder.toString(HashMap.class, map1, "name", map2));
- info(GridToStringBuilder.toString(HashMap.class, map2, "name", map1));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testToStringCheckObjectRecursionPrevention() throws Exception {
- Node n1 = new Node();
- Node n2 = new Node();
- Node n3 = new Node();
- Node n4 = new Node();
-
- n1.name = "n1";
- n2.name = "n2";
- n3.name = "n3";
- n4.name = "n4";
-
- n1.next = n2;
- n2.next = n3;
- n3.next = n4;
- n4.next = n3;
-
- n1.nodes = new Node[4];
- n2.nodes = n1.nodes;
- n3.nodes = n1.nodes;
- n4.nodes = n1.nodes;
-
- n1.nodes[0] = n1;
- n1.nodes[1] = n2;
- n1.nodes[2] = n3;
- n1.nodes[3] = n4;
-
- String expN1 = n1.toString();
- String expN2 = n2.toString();
- String expN3 = n3.toString();
- String expN4 = n4.toString();
-
- info(expN1);
- info(expN2);
- info(expN3);
- info(expN4);
- info(GridToStringBuilder.toString("Test", "Appended vals", n1));
-
- CyclicBarrier bar = new CyclicBarrier(4);
-
- IgniteInternalFuture<String> fut1 = GridTestUtils.runAsync(new BarrierCallable(bar, n1, expN1));
- IgniteInternalFuture<String> fut2 = GridTestUtils.runAsync(new BarrierCallable(bar, n2, expN2));
- IgniteInternalFuture<String> fut3 = GridTestUtils.runAsync(new BarrierCallable(bar, n3, expN3));
- IgniteInternalFuture<String> fut4 = GridTestUtils.runAsync(new BarrierCallable(bar, n4, expN4));
-
- fut1.get(3_000);
- fut2.get(3_000);
- fut3.get(3_000);
- fut4.get(3_000);
- }
-
- /**
- * Test class.
- */
- private static class Node {
- /** */
- @GridToStringInclude
- String name;
-
- /** */
- @GridToStringInclude
- Node next;
-
- /** */
- @GridToStringInclude
- Node[] nodes;
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return GridToStringBuilder.toString(Node.class, this);
- }
- }
-
- /**
- * Test class.
- */
- private static class BarrierCallable implements Callable<String> {
- /** */
- CyclicBarrier bar;
-
- /** */
- Object obj;
-
- /** Expected value of {@code toString()} method. */
- String exp;
-
- /** */
- private BarrierCallable(CyclicBarrier bar, Object obj, String exp) {
- this.bar = bar;
- this.obj = obj;
- this.exp = exp;
- }
-
- /** {@inheritDoc} */
- @Override public String call() throws Exception {
- for (int i = 0; i < 10; i++) {
- bar.await();
-
- assertEquals(exp, obj.toString());
- }
-
- return null;
- }
+ GridToStringBuilder.toString(ArrayList.class, list1, "name", list2);
+ GridToStringBuilder.toString(ArrayList.class, list2, "name", list1);
}
/**
@@ -275,33 +137,6 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
Arrays.fill(arrOf, v);
T[] arr = Arrays.copyOf(arrOf, limit);
- checkArrayOverflow(arrOf, arr, limit);
- }
-
- /**
- * Test array print.
- *
- * @throws Exception if failed.
- */
- public void testArrLimitWithRecursion() throws Exception {
- int limit = IgniteSystemProperties.getInteger(IGNITE_TO_STRING_COLLECTION_LIMIT, 100);
-
- ArrayList[] arrOf = new ArrayList[limit + 1];
- Arrays.fill(arrOf, new ArrayList());
- ArrayList[] arr = Arrays.copyOf(arrOf, limit);
-
- arrOf[0].add(arrOf);
- arr[0].add(arr);
-
- checkArrayOverflow(arrOf, arr, limit);
- }
-
- /**
- * @param arrOf Array.
- * @param arr Array copy.
- * @param limit Array limit.
- */
- private void checkArrayOverflow(Object[] arrOf, Object[] arr, int limit) {
String arrStr = GridToStringBuilder.arrayToString(arr.getClass(), arr);
String arrOfStr = GridToStringBuilder.arrayToString(arrOf.getClass(), arrOf);
@@ -309,11 +144,7 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
StringBuilder resultSB = new StringBuilder(arrStr);
resultSB.deleteCharAt(resultSB.length()-1);
resultSB.append("... and ").append(arrOf.length - limit).append(" more]");
-
- arrStr = resultSB.toString();
-
- info(arrOfStr);
- info(arrStr);
+ arrStr = resultSB.toString();
assertTrue("Collection limit error in array of type " + arrOf.getClass().getName()
+ " error, normal arr: <" + arrStr + ">, overflowed arr: <" + arrOfStr + ">", arrStr.equals(arrOfStr));
@@ -397,58 +228,18 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
strMap.put("k" + i, "v");
strList.add("e");
}
+ String testClassStr = GridToStringBuilder.toString(TestClass1.class, testClass);
- checkColAndMap(testClass);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testToStringColAndMapLimitWithRecursion() throws Exception {
- int limit = IgniteSystemProperties.getInteger(IGNITE_TO_STRING_COLLECTION_LIMIT, 100);
- Map strMap = new TreeMap<>();
- List strList = new ArrayList<>(limit+1);
-
- TestClass1 testClass = new TestClass1();
- testClass.strMap = strMap;
- testClass.strListIncl = strList;
-
- Map m = new TreeMap();
- m.put("m", strMap);
-
- List l = new ArrayList();
- l.add(strList);
-
- strMap.put("k0", m);
- strList.add(l);
-
- for (int i = 1; i < limit; i++) {
- strMap.put("k" + i, "v");
- strList.add("e");
- }
-
- checkColAndMap(testClass);
- }
-
- /**
- * @param testCls Class with collection and map included in toString().
- */
- private void checkColAndMap(TestClass1 testCls) {
- String testClsStr = GridToStringBuilder.toString(TestClass1.class, testCls);
-
- testCls.strMap.put("kz", "v"); // important to add last element in TreeMap here
- testCls.strListIncl.add("e");
+ strMap.put("kz", "v"); // important to add last element in TreeMap here
+ strList.add("e");
- String testClsStrOf = GridToStringBuilder.toString(TestClass1.class, testCls);
+ String testClassStrOf = GridToStringBuilder.toString(TestClass1.class, testClass);
- String testClsStrOfR = testClsStrOf.replaceAll("... and 1 more","");
+ String testClassStrOfR = testClassStrOf.replaceAll("... and 1 more","");
- info(testClsStr);
- info(testClsStrOf);
- info(testClsStrOfR);
+ assertTrue("Collection limit error in Map or List, normal: <" + testClassStr + ">, overflowed: <"
+ +"testClassStrOf", testClassStr.length() == testClassStrOfR.length());
- assertTrue("Collection limit error in Map or List, normal: <" + testClsStr + ">, overflowed: <"
- + testClsStrOf + ">", testClsStr.length() == testClsStrOfR.length());
}
/**
@@ -611,4 +402,4 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
this.str = str;
}
}
-}
+}
\ No newline at end of file
[2/3] ignite git commit: Revert "IGNITE-9209 fix for
GridDistributedTxMapping.toString() returns broken string. - Fixes #4519."
Posted by ni...@apache.org.
Revert "IGNITE-9209 fix for GridDistributedTxMapping.toString() returns broken string. - Fixes #4519."
This reverts commit 9bb9c043513c3cc6c6b70c6c3395e5bb76fad75e.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5f968d24
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5f968d24
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5f968d24
Branch: refs/heads/ignite-2.7
Commit: 5f968d2413c0c914da0ebcb5c051023429b3e518
Parents: e6b42ab
Author: Nikolay Izhikov <ni...@apache.org>
Authored: Fri Nov 23 22:51:45 2018 +0300
Committer: Nikolay Izhikov <ni...@apache.org>
Committed: Fri Nov 23 22:51:45 2018 +0300
----------------------------------------------------------------------
.../internal/util/tostring/GridToStringBuilder.java | 10 +++-------
.../util/tostring/GridToStringBuilderSelfTest.java | 13 -------------
2 files changed, 3 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f968d24/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
index 67b9af1..86daf7c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
@@ -985,7 +985,6 @@ public class GridToStringBuilder {
if (newStr)
return s;
- // Called from another GTSB.toString(), so this string is already in the buffer and shouldn't be returned.
return "";
}
finally {
@@ -1053,6 +1052,7 @@ public class GridToStringBuilder {
}
// Specifically catching all exceptions.
catch (Exception e) {
+
// Remove entry from cache to avoid potential memory leak
// in case new class loader got loaded under the same identity hash.
classCache.remove(cls.getName() + System.identityHashCode(cls.getClassLoader()));
@@ -1605,7 +1605,7 @@ public class GridToStringBuilder {
private static String toStringImpl(String str, SBLimitedLength buf, Object[] propNames, Object[] propVals,
boolean[] propSens, int propCnt) {
- boolean newStr = buf.length() == 0;
+ buf.setLength(0);
if (str != null)
buf.a(str).a(" ");
@@ -1616,11 +1616,7 @@ public class GridToStringBuilder {
buf.a(']');
- if (newStr)
- return buf.toString();
-
- // Called from another GTSB.toString(), so this string is already in the buffer and shouldn't be returned.
- return "";
+ return buf.toString();
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/5f968d24/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
index 9a9e67e..eff3349 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
@@ -31,8 +31,6 @@ import java.util.concurrent.locks.ReadWriteLock;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
-import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
@@ -479,17 +477,6 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest {
}
/**
- *
- */
- public void testObjectPlusStringToString() {
- IgniteTxKey k = new IgniteTxKey(new KeyCacheObjectImpl(1, null, 1), 123);
-
- info(k.toString());
-
- assertTrue("Wrong string: " + k, k.toString().startsWith("IgniteTxKey ["));
- }
-
- /**
* Test class.
*/
private static class TestClass1 {