[hg] main-silver: #210615: Cut the retrieved String if it's too ...

  • From:
  • To:
  • Subject: [hg] main-silver: #210615: Cut the retrieved String if it's too ...
  • Date: Wed, 09 Jan 2013 09:57:50 -0800

changeset e8257225118a in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/e8257225118a
description:
        #210615: Cut the retrieved String if it's too long to limit the 
memory consumption.

diffstat:

 
debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
 |   3 ++
 
debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractVariable.java
       |  11 ++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diffs (41 lines):

diff --git 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
--- 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
+++ 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
@@ -106,6 +106,8 @@
     
     private static final Logger logger = 
Logger.getLogger("org.netbeans.modules.debugger.jpda.getValue"); // NOI18N
 
+    static int MAX_STRING_LENGTH = 1000000; // Limit retrieved String length 
to 1M characters to limit memory consumption.
+
     private String          genericType;
     private Field[]         fields;
     private Field[]         staticFields;
@@ -464,6 +466,7 @@
             boolean addQuotation = false;
             boolean addDots = false;
             StringReference sr;
+            maxLength = (maxLength > 0 && maxLength < MAX_STRING_LENGTH) ? 
maxLength : MAX_STRING_LENGTH;
             if (maxLength > 0 && maxLength < Integer.MAX_VALUE) {
                 Method toStringMethod = 
ClassTypeWrapper.concreteMethodByName(ct,
                      "toString", "()Ljava/lang/String;");  // NOI18N
diff --git 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractVariable.java
 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractVariable.java
--- 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractVariable.java
+++ 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractVariable.java
@@ -161,10 +161,13 @@
         if (v instanceof PrimitiveValue)
             return v.toString ();
         try {
-            if (v instanceof StringReference)
-                return "\"" +
-                    StringReferenceWrapper.value((StringReference) v)
-                    + "\"";
+            if (v instanceof StringReference) {
+                String str = StringReferenceWrapper.value((StringReference) 
v);
+                if (str.length() > AbstractObjectVariable.MAX_STRING_LENGTH) 
{
+                    str = str.substring(0, 
AbstractObjectVariable.MAX_STRING_LENGTH) + "..."; // NOI18N
+                }
+                return "\"" + str + "\"";
+            }
             if (v instanceof ClassObjectReference)
                 return "class " + 
ReferenceTypeWrapper.name(ClassObjectReferenceWrapper.reflectedType((ClassObjectReference)
 v));
             if (v instanceof ArrayReference)

[hg] main-silver: #210615: Cut the retrieved String if it's too ...

mentlicher 01/09/2013

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close