[hg] main-silver: #237964, #237576: invalid fold requests ignored

  • From: Svata Dedic < >
  • To:
  • Subject: [hg] main-silver: #237964, #237576: invalid fold requests ignored
  • Date: Thu, 07 Nov 2013 21:53:50 +0000

changeset 91d00c751468 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/91d00c751468
description:
        #237964, #237576: invalid fold requests ignored

diffstat:

 editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java |  
29 ++++++++-
 1 files changed, 26 insertions(+), 3 deletions(-)

diffs (73 lines):

diff --git 
a/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java 
b/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java
--- a/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java
+++ b/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java
@@ -571,14 +571,17 @@
                 if (nextInfo != null) {
                     f = nextInfo;
                     nextInfo = null;
+                    if (isValidFold(f)) {
                     return f;
-                } else if (infoIt.hasNext()) {
+                    }
+                } 
+                if (infoIt.hasNext()) {
                     f = infoIt.next();
                 } else {
                     return null;
                 }
                 // ignore folds with invalid boundaries
-            } while (f.getStart() >= f.getEnd());
+            } while (!isValidFold(f));
             return f;
         }
         
@@ -635,6 +638,23 @@
             return f;
         }
         
+        /**
+         * Validates the FoldInfo. Because of issue #237964, #237576 and 
similar, it is better 
+         * to check that the FoldInfo does not contain invalid data 
centrally. The original idea was
+         * to inform the fold manager early, but the issue seems hardly 
fixable at source
+         * @param fi fold info to check
+         * @return true, if the info is valid and should proceed to fold 
creation / update
+         */
+        private boolean isValidFold(FoldInfo fi) {
+            // disallow zero-length folds and reversed folds.
+            if (fi.getStart() >= fi.getEnd()) {
+                return false;
+            }
+            int glen = fi.getTemplate().getGuardedEnd() + 
fi.getTemplate().getGuardedStart();
+            // disallow folds, whiose length is less than the length of 
start/end guarded areas.
+            return (fi.getStart() + glen <= fi.getEnd());
+        }
+        
         public void run() throws BadLocationException {
             // first order the supplied folds:
             List ll = new ArrayList<FoldInfo>(foldInfos);
@@ -644,7 +664,7 @@
             infoIt = ll.iterator();
             
             Fold f = foldIt.hasNext() ? foldIt.next() : null;
-            FoldInfo i = infoIt.hasNext() ? infoIt.next() : null;
+            FoldInfo i = ni();
             
             tran = openTransaction();
             Document d = getDocument();
@@ -721,6 +741,8 @@
                             // invalid fold info; possibly document has 
changed from the time FoldInfo was created.
                             continue;
                         }
+                        /*
+                        FoldInfos which do not satisfy this condition are 
filtered out in isValidFold()
                         if ((info.getEnd() - info.getStart()) < 
(info.getTemplate().getGuardedStart() + info.getTemplate().getGuardedEnd())) {
                             Element rootEl = 
DocumentUtilities.getParagraphRootElement(d);
                             int startLine = 
rootEl.getElementIndex(info.getStart());
@@ -744,6 +766,7 @@
                                         text.substring(end)
                                     });
                         }
+                        */
                         currentFolds.put(info, getOperation().addToHierarchy(
                                 info.getType(), 
                                 info.getStart(), info.getEnd(),

[hg] main-silver: #237964, #237576: invalid fold requests ignored

Svata Dedic 11/07/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 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