classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Add exception cause to swing.text assertion errors


From: Mark Wielaard
Subject: [cp-patches] FYI: Add exception cause to swing.text assertion errors
Date: Sun, 30 Oct 2005 18:59:47 +0100

Hi,

Both our Free Swing Demo and the beanshell swing interface throw
AssertionErrors about unexpected exceptions. this patch adds the cause
to these exceptions before throwing and actually throw an AssertionError
that was constructed but then not thrown at all. This helps a lot with
trying to debug these kind of "internal" asserts.

2005-10-30  Mark Wielaard  <address@hidden>

   * javax/swing/text/AbstractDocument.java (dump): Actually throw
   AssertionError when constructed.
   * javax/swing/text/DefaultFormatter.java (checkValidInput): Add cause
   to AssertionError.
   * javax/swing/text/DefaultStyledDocument.java (insertUpdate):
   Likewise.
   * javax/swing/text/GlyphView.java (getPartialSpan): Likewise.
   (getText): Likewise.
   * javax/swing/text/PlainView.java (determineMaxLineLength): Likewise.
   (updateDamage): Likewise.

This shows the following cause for an assertion exception when running
our Demo:

Caused by: javax.swing.text.BadLocationException: len plus where cannot be 
greater than the content length
   at javax.swing.text.GapContent.getChars (GapContent.java:405)
   at javax.swing.text.AbstractDocument.getText (AbstractDocument.java:518)
   at javax.swing.text.PlainView.determineMaxLineLength (PlainView.java:254)
   ...41 more

Not yet investigated.
The workaround for now is running with -Dswing.defaultlaf set.

Committed,

Mark
Index: javax/swing/text/AbstractDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/AbstractDocument.java,v
retrieving revision 1.36
diff -u -r1.36 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java      27 Oct 2005 14:53:42 -0000      
1.36
+++ javax/swing/text/AbstractDocument.java      30 Oct 2005 17:49:07 -0000
@@ -1556,6 +1556,7 @@
                                                       + "must not be thrown "
                                                       + "here.");
               err.initCause(ex);
+             throw err;
             }
           b.append("]\n");
         }
Index: javax/swing/text/DefaultFormatter.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultFormatter.java,v
retrieving revision 1.4
diff -u -r1.4 DefaultFormatter.java
--- javax/swing/text/DefaultFormatter.java      13 Sep 2005 23:44:50 -0000      
1.4
+++ javax/swing/text/DefaultFormatter.java      30 Oct 2005 17:49:07 -0000
@@ -175,7 +175,10 @@
               catch (ParseException pe)
                 {
                   // if that happens, something serious must be wrong
-                  throw new AssertionError("values must be parseable");
+                  AssertionError ae;
+                 ae = new AssertionError("values must be parseable");
+                 ae.initCause(pe);
+                 throw ae;
                 }
             }
         }
Index: javax/swing/text/DefaultStyledDocument.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v
retrieving revision 1.13
diff -u -r1.13 DefaultStyledDocument.java
--- javax/swing/text/DefaultStyledDocument.java 20 Sep 2005 14:53:47 -0000      
1.13
+++ javax/swing/text/DefaultStyledDocument.java 30 Oct 2005 17:49:07 -0000
@@ -1073,8 +1073,9 @@
       }
     catch (BadLocationException ex)
       {
-        throw new AssertionError("BadLocationException must not be thrown "
-                                 + "here.");
+        AssertionError ae = new AssertionError("Unexpected bad location");
+       ae.initCause(ex);
+       throw ae;
       }
 
     int len = 0;
Index: javax/swing/text/GlyphView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GlyphView.java,v
retrieving revision 1.9
diff -u -r1.9 GlyphView.java
--- javax/swing/text/GlyphView.java     19 Oct 2005 14:57:31 -0000      1.9
+++ javax/swing/text/GlyphView.java     30 Oct 2005 17:49:07 -0000
@@ -666,8 +666,11 @@
       }
     catch (BadLocationException ex)
       {
-        throw new AssertionError("BadLocationException must not be thrown "
-                                 + "here");
+       AssertionError ae;
+        ae = new AssertionError("BadLocationException must not be thrown "
+                               + "here");
+       ae.initCause(ex);
+       throw ae;
       }
     FontMetrics fm = null; // Fetch font metrics somewhere.
     return Utilities.getTabbedTextWidth(seg, fm, 0, null, p0);
@@ -714,8 +717,11 @@
       }
     catch (BadLocationException ex)
       {
-        throw new AssertionError("BadLocationException should not be "
-                                 + "thrown here. p0 = " + p0 + ", p1 = " + p1);
+       AssertionError ae;
+        ae = new AssertionError("BadLocationException should not be "
+                               + "thrown here. p0 = " + p0 + ", p1 = " + p1);
+       ae.initCause(ex);
+       throw ae;
       }
 
     return txt;
Index: javax/swing/text/PlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v
retrieving revision 1.27
diff -u -r1.27 PlainView.java
--- javax/swing/text/PlainView.java     19 Oct 2005 14:57:32 -0000      1.27
+++ javax/swing/text/PlainView.java     30 Oct 2005 17:49:07 -0000
@@ -255,7 +255,9 @@
           }
         catch (BadLocationException ex)
           {
-            assert false : "BadLocationException should not be thrown here.";
+            AssertionError ae = new AssertionError("Unexpected bad location");
+           ae.initCause(ex);
+           throw ae;
           }
         
         if (seg == null || seg.array == null || seg.count == 0)
@@ -416,7 +418,9 @@
           }
         catch (BadLocationException ex)
           {
-            assert false : "BadLocationException should not be thrown here.";
+            AssertionError ae = new AssertionError("Unexpected bad location");
+           ae.initCause(ex);
+           throw ae;
           }
                 
         if (seg == null || seg.array == null || seg.count == 0)

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]