Skip to content

Commit

Permalink
IGNITE-9209 fix for GridDistributedTxMapping.toString() returns broke…
Browse files Browse the repository at this point in the history
…n string. - Fixes #4519.

Signed-off-by: Dmitriy Pavlov <dpavlov@apache.org>
  • Loading branch information
SomeFire authored and dspavlov committed Aug 14, 2018
1 parent 2fc9073 commit 9bb9c04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -985,6 +985,7 @@ private static <T> String toStringImpl(
if (newStr)
return s;

// Called from another GTSB.toString(), so this string is already in the buffer and shouldn't be returned.
return "";
}
finally {
Expand Down Expand Up @@ -1052,7 +1053,6 @@ private static <T> String toStringImpl0(
}
// 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()));
Expand Down Expand Up @@ -1605,7 +1605,7 @@ public static String toString(String str,
private static String toStringImpl(String str, SBLimitedLength buf, Object[] propNames, Object[] propVals,
boolean[] propSens, int propCnt) {

buf.setLength(0);
boolean newStr = buf.length() == 0;

if (str != null)
buf.a(str).a(" ");
Expand All @@ -1616,7 +1616,11 @@ private static String toStringImpl(String str, SBLimitedLength buf, Object[] pro

buf.a(']');

return buf.toString();
if (newStr)
return buf.toString();

// Called from another GTSB.toString(), so this string is already in the buffer and shouldn't be returned.
return "";
}

/**
Expand Down
Expand Up @@ -31,6 +31,8 @@
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;
Expand Down Expand Up @@ -476,6 +478,17 @@ public void testToStringSizeLimits() throws Exception {
assertTrue(actual.contains("skipped ..."));
}

/**
*
*/
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.
*/
Expand Down

0 comments on commit 9bb9c04

Please sign in to comment.