[testng] 121/355: Fix OutOfMemoryError: use hash codes as keys to the method map.

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:19:55 UTC 2015


This is an automated email from the git hooks/post-receive script.

eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.

commit c9a91722631f3b2f9bcc5a300e7a84c61cd4764f
Author: Cedric Beust <cedric at beust.com>
Date:   Tue Jan 13 13:35:16 2015 -0800

    Fix OutOfMemoryError: use hash codes as keys to the method map.
    
    Better than using TestResult, which can contain entire bitmaps.
    
    Note: hashCode() is not overridden in TestResult but I'm using it anyway. Tiny window for a bug here.
---
 src/main/java/org/testng/Reporter.java | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/testng/Reporter.java b/src/main/java/org/testng/Reporter.java
index 01f8f36..b2f30eb 100755
--- a/src/main/java/org/testng/Reporter.java
+++ b/src/main/java/org/testng/Reporter.java
@@ -1,13 +1,13 @@
 package org.testng;
 
-import org.testng.collections.Lists;
-import org.testng.collections.Maps;
-import org.testng.util.Strings;
-
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
 
+import org.testng.collections.Lists;
+import org.testng.collections.Maps;
+import org.testng.util.Strings;
+
 /**
  * This class is used for test methods to log messages that will be
  * included in the HTML reports generated by TestNG.
@@ -18,8 +18,8 @@ import java.util.Vector;
  * <br>
  * The reporter keeps a combined output of strings (in m_output) and also
  * a record of which method output which line.  In order to do this, callers
- * specify what the current method is with setCurrentMethod() and the
- * Reporter maintaing a mapping of each method with a list of integers.
+ * specify what the current method is with setCurrentTestResult() and the
+ * Reporter maintaing a mapping of each test result with a list of integers.
  * These integers are indices in the combined output (avoids duplicating
  * the output).
  *
@@ -37,7 +37,8 @@ public class Reporter {
    */
   private static List<String> m_output = new Vector<String>();
 
-  private static Map<ITestResult, List<Integer>> m_methodOutputMap = Maps.newHashMap();
+  /** The key is the hashCode of the ITestResult */
+  private static Map<Integer, List<Integer>> m_methodOutputMap = Maps.newHashMap();
 
   private static boolean m_escapeHtml = false;
 
@@ -72,10 +73,10 @@ public class Reporter {
 
     // synchronization needed to ensure the line number and m_output are updated atomically
     int n = getOutput().size();
-    List<Integer> lines = m_methodOutputMap.get(m);
+    List<Integer> lines = m_methodOutputMap.get(m.hashCode());
     if (lines == null) {
       lines = Lists.newArrayList();
-      m_methodOutputMap.put(m, lines);
+      m_methodOutputMap.put(m.hashCode(), lines);
     }
     lines.add(n);
     getOutput().add(s);
@@ -144,7 +145,7 @@ public class Reporter {
 
   public static synchronized List<String> getOutput(ITestResult tr) {
     List<String> result = Lists.newArrayList();
-    List<Integer> lines = m_methodOutputMap.get(tr);
+    List<Integer> lines = m_methodOutputMap.get(tr.hashCode());
     if (lines != null) {
       for (Integer n : lines) {
         result.add(getOutput().get(n));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git



More information about the pkg-java-commits mailing list