12 Replies Latest reply on Mar 19, 2007 3:22 PM by 807599

    inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker thread

    807599
      On occasions I will get the following exception thrown whenever I happen to be using SimpleBrowser.this.processor.processTask() method to run a SwingWorker<Void, Void>-based class Task worker thread (within doInBackground()) :
      Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
              at javax.swing.text.BoxView.getOffset(BoxView.java:1076)
              at javax.swing.text.BoxView.childAllocation(BoxView.java:670)
              at javax.swing.text.CompositeView.getChildAllocation(CompositeView.java:215)
              at javax.swing.text.BoxView.getChildAllocation(BoxView.java:428)
              at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.calculateViewPosition(BasicTextUI.java:1978)
              at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.layoutContainer(BasicTextUI.java:1954)
              at java.awt.Container.layout(Container.java:1432)
              at java.awt.Container.doLayout(Container.java:1421)
              at java.awt.Container.validateTree(Container.java:1519)
              at java.awt.Container.validateTree(Container.java:1526)
              at java.awt.Container.validateTree(Container.java:1526)
              at java.awt.Container.validate(Container.java:1491)
              at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:639)
              at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:127)
              at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
              at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
      I haven't found much reliable online information to illustrate this issue any further so I'm a bit in the dark. Following is my code that runs within the aforementioned worker thread which I believe throws the exception:
             /**
               * Use {@link #setWebBrowserURL} using a local {@link com.ppowell.tools.ObjectTools.SwingTools.Task}
               */
              protected void processTask() {
                  Task task = new Task() {
                      public Void doInBackground() {
                          int progress = 0;
                          while (!SimpleBrowser.this.builder.hasLoadedWebpage && progress < 100) {
                              SimpleBrowser.this.statusBar.setMessage("Attempting to load " + SimpleBrowser.this.getURL().toString());
                              this.setProgress(progress);
                              progress++;
                          }
                          SimpleBrowser.this.setWebBrowserURL();
                          try {
                              Thread.sleep(2500);
                          } catch (InterruptedException ignore) {} // DO NOTHING
                          if (SimpleBrowser.this.builder.hasLoadedWebpage) {
                              SimpleBrowser.this.statusBar.setMessage("Done");
                          }
                          return null;
                      }
                  };
                  task.addPropertyChangeListener(SimpleBrowser.this);
                  task.execute();
              }
      Is there a way I might at least be able to suppress this error (the GUI application browser functions just fine in spite of it), or, even better, solve this inconsistent problem?

      Thanks
      Phil
        • 1. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker thread
          796447
          I don't know, but I'd have to suspect that the very tight loop which starts at this line:
          while (!SimpleBrowser.this.builder.hasLoadedWebpage && progress < 100) {
          is at least some kind of problem. You should probably use some kind of wait/notify scheme instead of a tight polling scheme.
          • 2. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
            807599
            wait/notify scheme = ?

            polling scheme = ?

            Sorry your terminology confuses me.
            • 3. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
              796447
              http://www.google.com/search?hl=en&q=java+wait+notify
              As for polling,
              http://en.wikipedia.org/wiki/Polling_%28computer_science%29
              • 4. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
                807599
                polling I/O makes 0% sense to me, I'm a web guy I wouldn't know stuff like polling.. to me it's a plain ol' while loop.
                • 5. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
                  796447
                  polling I/O makes 0% sense to me, I'm a web
                  guy
                  I wouldn't know stuff like polling.. to me
                  it's a plain ol' while loop.
                  Well I tried to get it defined for you. All I'll say in addition is that polling, simply defined, is:
                  Checking something over and over in a loop until something changes (or until some other condition is met, such as in your case, a counter reaches a certain value) all the while sucking up the processor's time it could be spent on doing something useful.

                  Here's another link which may provide more info or spur you to do more research:
                  http://www.google.com/search?hl=en&q=define%3Apolling
                  • 6. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
                    807599
                    polling I/O makes 0% sense to me, I'm a web
                    guy
                    I wouldn't know stuff like polling.. to me
                    it's a plain ol' while loop.
                    Well I tried to get it defined for you. All I'll say
                    in addition is that polling, simply defined, is:
                    Checking something over and over in a loop until
                    something changes (or until some other condition is
                    met, such as in your case, a counter reaches a
                    certain value) all the while sucking up the
                    processor's time it could be spent on doing something
                    useful.
                    That makes a thousand times more sense, thanx, though the term "polling" is very foreign to me (we call them finite conditional loops), but anyway

                    I am still getting the intermittent ArrayIndexOutOfBoundsException -1 which is untraceable (at least by me) due to the stack solely pointing to AWT, EventQueue, or various threads native to the Java core, and it doesn't always occur, so I have no idea how to stop it or at least suppress it.

                    Perhaps if I let you look at the code entrenched within the event dispatch thread, not sure if that will help but oh why not:
                      /**
                         * Set {@link #browser} with either instantiable {@link java.net.URL} or with {@link #DEFAULT_URL_PATH}
                         */
                        private void setWebBrowserURL() {
                            try {
                                URL url = getURL();
                                String urlPath = getURLPath();
                                if (urlPath != null && !urlPath.equals("")) {
                                    setURL(new URL(urlPath));
                                } else {
                                    setURL(new URL(SimpleBrowser.DEFAULT_URL_PATH));
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                handleErrors();
                            } finally {
                                try {
                                    if (urlPath != null && !urlPath.equals("")) {
                                        setURL(new URL(urlPath));
                                    } else {
                                        setURL(new URL(SimpleBrowser.DEFAULT_URL_PATH));
                                    }
                                    if (!SimpleBrowser.this.browser.compareURLTo(getURL())) {
                                        SimpleBrowser.this.browser.setPage(getURL());
                                    }
                                    SimpleBrowser.this.builder.hasLoadedWebpage = true;
                                } catch (ConnectException e) {
                                    handleErrors(getURL(), e);
                                    System.exit(0);
                                } catch (UnknownHostException e2) {
                                    handleErrors(getURL(), e2);
                                    System.exit(0);
                                } catch (Exception e3) {
                                    System.out.println("error!");
                                    e3.printStackTrace();
                                    handleErrors();
                                    System.exit(0);
                                }
                            }
                        }
                    Here's another link which may provide more info or
                    spur you to do more research:
                    http://www.google.com/search?hl=en&q=define%3Apolling
                    • 7. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
                      807599
                      Well, according to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5052320 Sun is telling me this is a NetBeans bug whenever you use UIManager.setLookAndFeel.
                      • 8. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
                        807599
                        That might be the problem, however, according to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4695909 the problem may also be due to JEditorPane containing HTML which contains a <META> tag and/or <!-- comment tag -->. I created a class SimpleHTMLRenderableEditorPane which extends JEditorPane, based upon code I found in the aformentioned bug link which should auto-strip out "bad tags":
                        /*
                         * SimpleHTMLRenderableEditorPane.java
                         *
                         * Created on March 13, 2007, 3:39 PM
                         *
                         * To change this template, choose Tools | Template Manager
                         * and open the template in the editor.
                         */
                        
                        package com.ppowell.tools.ObjectTools.SwingTools;
                        
                        import javax.swing.JEditorPane;
                        
                        /**
                         * A safer version of {@link javax.swing.JEditorPane}
                         * @author Phil Powell
                         * @version JDK 1.6.0
                         */
                        public class SimpleHTMLRenderableEditorPane extends JEditorPane {
                            
                            //--------------------------- --* CONSTRUCTORS *-- ---------------------------
                            // <editor-fold defaultstate="collapsed" desc=" Constructors ">    
                            /** Creates a new instance of SimpleHTMLRenderableEditorPane */
                            public SimpleHTMLRenderableEditorPane() {
                                super();
                            }
                            // </editor-fold>
                            //----------------------- --* GETTER/SETTER METHODS *-- ----------------------
                            // <editor-fold defaultstate="collapsed" desc=" Getter/Setter Methods ">
                            /**
                             * Overloaded to fix HTML rendering bug Bug ID: 4695909.
                             * @param text
                             */
                            public void setText(String text) {
                                // Workaround for bug Bug ID: 4695909 in java 1.4
                                // JEditorPane does not handle the META tag in the html HEAD
                                if (isJava14() && "text/html".equalsIgnoreCase(getContentType())) {
                                    text = stripMetaTag(text);
                                }
                                super.setText(text);
                            }
                            // </editor-fold>
                            //--------------------------- --* OTHER METHODS *-- --------------------------
                            // <editor-fold defaultstate="collapsed" desc=" Methods ">
                            /**
                             * Clean HTML to remove things like <script>, <style>, <object>, <embed>, and <!-- -->
                             * Based upon <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4695909">bug report</a>
                             */
                            public void cleanHTML() {
                                try {
                                    String html = getText();
                                    if (html != null && !html.equals("")) {
                                        String[] patternArray = {
                                            "<script[^>]*>[^<]*(</script>)?",
                                            "<style[^>]*>[^<]*(</style>)?>",
                                            "<object[^>]*>[^<]*(</object>)?>",
                                            "<embed[^>]*>[^<]*(</embed>)?>",
                                            "<!\\-\\-.*\\-\\->"
                                        };
                                        for (int i = 0; i < patternArray.length; i++) {
                                            html = html.replaceAll(patternArray, "");
                        }
                        setText(html);
                        }
                        } catch (Exception e) {} // DO NOTHING
                        }

                        /**
                        * Determine if java version is 1.4.
                        * @return true if java version is 1.4.x....
                        */
                        private boolean isJava14() {
                        String version = System.getProperty("java.version");
                        return version.startsWith("1.4");
                        }

                        /**
                        * Workaround for Bug ID: 4695909 in java 1.4, fixed in 1.5
                        * JEditorPane fails to display HTML BODY when META
                        * tag included in HEAD section.
                        *
                        * <html>
                        * <head>
                        * <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
                        * </head>
                        * <body>
                        *
                        * @param text html to strip.
                        * @return same HTML text w/o the META tag.
                        */
                        private String stripMetaTag(String text) {
                        // String used for searching, comparison and indexing
                        String textUpperCase = text.toUpperCase();

                        int indexHead = textUpperCase.indexOf("<META ");
                        int indexMeta = textUpperCase.indexOf("<META ");
                        int indexBody = textUpperCase.indexOf("<BODY ");

                        // Not found or meta not inside the head nothing to strip...
                        if (indexMeta == -1 || indexMeta > indexHead && indexMeta < indexBody) {
                        return text;
                        }

                        // Find end of meta tag text.
                        int indexHeadEnd = textUpperCase.indexOf(">", indexMeta);

                        // Strip meta tag text
                        return text.substring(0, indexMeta-1) + text.substring(indexHeadEnd+1);
                        }
                        // </editor-fold>
                        }

                        However, upon running the following line:
                        SimpleBrowser.this.browser.cleanHTML();
                        I spawn the following exception:
                        Exception in thread "Thread-2" java.lang.RuntimeException: Must insert new content into body element-
                                at javax.swing.text.html.HTMLDocument$HTMLReader.generateEndsSpecsForMidInsert(HTMLDocument.java:1961)
                                at javax.swing.text.html.HTMLDocument$HTMLReader.<init>(HTMLDocument.java:1908)
                                at javax.swing.text.html.HTMLDocument$HTMLReader.<init>(HTMLDocument.java:1782)
                                at javax.swing.text.html.HTMLDocument$HTMLReader.<init>(HTMLDocument.java:1777)
                                at javax.swing.text.html.HTMLDocument.getReader(HTMLDocument.java:137)
                                at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:228)
                                at javax.swing.JEditorPane.read(JEditorPane.java:556)
                                at javax.swing.JEditorPane$PageLoader.run(JEditorPane.java:647)
                        What should I do at this point?

                        Thanks
                        Phil
                        • 9. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
                          807599
                          I suspect that you need to "clean" your html prior to calling super.setText(). My guess is that you're yanking nodes from beaneath Swing while it's trying to render.

                          In addition to that, you may want to use JTidy to clean up your html, and convert it to xhtml -- again prior to calling super.setText().
                          • 10. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
                            807599
                            I suspect that you need to "clean" your html prior to
                            calling super.setText(). My guess is that you're
                            yanking nodes from beaneath Swing while it's trying
                            to render.

                            In addition to that, you may want to use JTidy to
                            clean up your html, and convert it to xhtml -- again
                            prior to calling super.setText().
                            Problem is that however I clean up the HTML, the moment I try to reinsert back into the JEditorPane using setText(), I get EmptyStackException or I'll get NullPointerException or it just might work - same problem, different exception(s).
                            • 11. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
                              807599
                              I suspect that you need to "clean" your html prior
                              to
                              calling super.setText(). My guess is that you're
                              yanking nodes from beaneath Swing while it's
                              trying
                              to render.

                              In addition to that, you may want to use JTidy to
                              clean up your html, and convert it to xhtml --
                              again
                              prior to calling super.setText().
                              Problem is that however I clean up the HTML, the
                              moment I try to reinsert back into the JEditorPane
                              using setText(), I get EmptyStackException or I'll
                              get NullPointerException or it just might work - same
                              problem, different exception(s).
                              Ok this time I am simply using setText() instead of setPage(), but the results are, while consistent, they are consistently completely wrong. The browser appears blank every time, no HTML can be retrieved (you get a NullPointerException if you try), all the while I can verify that that original HTML from the remote site is correct, it never, ever, inserts into JEditorPane.

                              Here is my code:
                              /*
                               * SimpleHTMLRenderableEditorPane.java
                               *
                               * Created on March 13, 2007, 3:39 PM
                               *
                               * To change this template, choose Tools | Template Manager
                               * and open the template in the editor.
                               */
                              
                              package com.ppowell.tools.ObjectTools.SwingTools;
                              
                              import java.io.*;
                              import java.net.*;
                              import javax.swing.JEditorPane;
                              import javax.swing.text.html.HTMLEditorKit;
                              
                              /**
                               * A safer version of {@link javax.swing.JEditorPane}
                               * @author Phil Powell
                               * @version JDK 1.6.0
                               */
                              public class SimpleHTMLRenderableEditorPane extends JEditorPane {
                              
                                  //--------------------------- --* CONSTRUCTORS *--
                              ---------------------------
                                  // <editor-fold defaultstate="collapsed" desc=" Constructors ">
                                  /** Creates a new instance of SimpleHTMLRenderableEditorPane */
                                  public SimpleHTMLRenderableEditorPane() {
                                      super();
                                  }
                              
                                  /**
                                   * Creates a new instance of SimpleHTMLRenderableEditorPane
                                   * @param url {@link java.lang.String}
                                   * @throws java.io.IOException Thrown if an I/O exception occurs
                                   */
                                  public SimpleHTMLRenderableEditorPane(String url) throws
                              IOException {
                                      super(url);
                                  }
                              
                                  /**
                                   * Creates a new instance of SimpleHTMLRenderableEditorPane
                                   * @param type {@link java.lang.String}
                                   * @param text {@link java.lang.String}
                                   */
                                  public SimpleHTMLRenderableEditorPane(String type, String text) {
                                      super(type, text);
                                  }
                              
                                  /**
                                   * Creates a new instance of SimpleHTMLRenderableEditorPane
                                   * @param url {@link java.net.URL}
                                   * @throws java.io.IOException Thrown if an I/O exception occurs
                                   */
                                  public SimpleHTMLRenderableEditorPane(URL url) throws IOException
                              {
                                      super(url);
                                  }
                                  // </editor-fold>
                                  //----------------------- --* GETTER/SETTER METHODS *--
                              ----------------------
                                  // <editor-fold defaultstate="collapsed" desc=" Getter/Setter
                              Methods ">
                                  /**
                                   * Retrieve HTML content
                                   * @return html {@link java.lang.String}
                                   */
                                  public String getText() {
                                      try {
                                          /**
                                           * I decided to use {@link java.net.HttpURLConnection} to
                              retrieve the
                                           * HTML code from the remote site instead of using
                              super.getText() because
                                           * of the HTML code return constantly being stripped to
                              primitive HTML
                                           * template formatting irregardless of the original HTML
                              source code
                                           */
                                          HttpURLConnection conn =
                              (HttpURLConnection)getPage().openConnection();
                                          conn.setUseCaches(false);
                                          conn.setDefaultUseCaches(false);
                                          conn.setDoOutput(false); // READ-ONLY
                                          BufferedReader in = new BufferedReader(
                                                  new InputStreamReader(
                                                  conn.getInputStream()));
                                          int data;
                                          StringBuffer sb = new StringBuffer();
                                          char[] ch = new char[512];
                                          while ((data = in.read(ch)) != -1) {
                                              sb.append(ch, 0, data);
                                          }
                                          in.close();
                                          conn.disconnect();
                                          return sb.toString();
                                      } catch (IOException e) {
                                          return super.getText(); // DEFAULT TO USING
                              super.getText() IF NO I/O CONNECTION
                                      }
                                  }
                              
                                  /**
                                   * Overloaded to fix HTML rendering bug Bug ID: 4695909.
                                   * @param text {@link java.lang.String}
                                   */
                                  public void setText(String text) {
                                      // Workaround for bug Bug ID: 4695909 in java 1.4
                                      // JEditorPane does not handle the META tag in the html HEAD
                                      if (isJava14() && "text/
                              html".equalsIgnoreCase(getContentType())) {
                                          text = stripMetaTag(text);
                                      }
                                      super.setText(text);
                                  }
                                  // </editor-fold>
                                  //--------------------------- --* OTHER METHODS *--
                              --------------------------
                                  // <editor-fold defaultstate="collapsed" desc=" Methods ">
                                  /**
                                   * Clean HTML to remove things like <link>, <script>,
                                   * <style>, <object>, <embed>, and <!-- -->
                                   * Based upon <a href="http://bugs.sun.com/bugdatabase/view_bug.do?
                              bug_id=4695909">bug report</a>
                                   */
                                  public void cleanHTML() {
                                      try {
                                          setText(cleanHTML(getText()));
                                      } catch (Exception e) {} // DO NOTHING
                                  }
                              
                                  /**
                                   * Clean HTML
                                   * @param html {@link java.lang.String}
                                   * @return html {@link java.lang.String}
                                   */
                                  public String cleanHTML(String html) {
                                      String[] tagArray = {"<LINK", "<SCRIPT", "<STYLE", "<OBJECT",
                              "<EMBED", "<!--"};
                                      String upperHTML = html.toUpperCase();
                                      String endTag;
                                      int index = -1, endIndex = -1;
                                      for (int i = 0; i < tagArray.length; i++) {
                                          index = upperHTML.indexOf(tagArray);
                              endTag = "</" + tagArray[i].substring(1,
                              tagArray[i].length());
                              endIndex = upperHTML.indexOf(endTag, index);
                              while (index >= 0) {
                              if (endIndex >= 0) {
                              html = html.substring(0, index) +
                              html.substring(html.indexOf(">", endIndex)
                              + 1,
                              html.length());
                              upperHTML = upperHTML.substring(0, index) +
                              upperHTML.substring(upperHTML.indexOf(">",
                              endIndex) + 1,
                              upperHTML.length());
                              } else {
                              html = html.substring(0, index) +
                              html.substring(html.indexOf(">", index) +
                              1,
                              html.length());
                              upperHTML = upperHTML.substring(0, index) +
                              upperHTML.substring(upperHTML.indexOf(">",
                              index) + 1,
                              upperHTML.length());
                              }
                              index = upperHTML.indexOf(tagArray[i]);
                              endIndex = upperHTML.indexOf(endTag, index);
                              }
                              }
                              // REF: http://forum.java.sun.com/thread.jspa?threadID=213582&messageID=735120
                              html = html.substring(0, upperHTML.indexOf(">",
                              upperHTML.indexOf("</HTML")) + 1);
                              // REF: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5042872
                              return html.trim();
                              }

                              /**
                              * This actually only obtains the URL; this serves as a retriever
                              for cleanHTML(String html)
                              * @param url {@link java.net.URL}
                              * @return html {@link java.lang.String}
                              */
                              public String cleanHTML(URL url) {
                              try {
                              HttpURLConnection conn =
                              (HttpURLConnection)url.openConnection();
                              conn.setUseCaches(false);
                              conn.setDefaultUseCaches(false);
                              conn.setDoOutput(false); // READ-ONLY
                              BufferedReader in = new BufferedReader(
                              new InputStreamReader(
                              conn.getInputStream()));
                              int data;
                              StringBuffer sb = new StringBuffer();
                              char[] ch = new char[512];
                              while ((data = in.read(ch)) != -1) {
                              sb.append(ch, 0, data);
                              }
                              in.close();
                              conn.disconnect();
                              return cleanHTML(sb.toString());
                              } catch (IOException e) {
                              e.printStackTrace();
                              return null;
                              }
                              }

                              /**
                              * Determine if java version is 1.4.
                              * @return true if java version is 1.4.x....
                              */
                              private boolean isJava14() {
                              if (System.getProperty("java.version") == null) return false;
                              return System.getProperty("java.version").startsWith("1.4");
                              }

                              /**
                              * Workaround for Bug ID: 4695909 in java 1.4, fixed in 1.5
                              * JEditorPane fails to display HTML BODY when META tag included
                              in HEAD section.
                              *
                              * Code modified by Phil Powell
                              *
                              * <html>
                              * <head>
                              * <META http-equiv="Content-Type" content="text/html;
                              charset=UTF-8">
                              * </head>
                              * <body>
                              * @param text html to strip.
                              * @return same HTML text w/o the META tag.
                              */
                              private String stripMetaTag(String text) {
                              // String used for searching, comparison and indexing
                              String textUpperCase = text.toUpperCase();

                              int indexHead = textUpperCase.indexOf("<HEAD ");
                              int indexMeta = textUpperCase.indexOf("<META ");
                              int indexBody = textUpperCase.indexOf("<BODY ");

                              // Not found or meta not inside the head nothing to strip...
                              if (indexMeta == -1 || indexMeta < indexHead || indexMeta >
                              indexBody) {
                              return text;
                              }

                              // Find end of meta tag text.
                              int indexHeadEnd = textUpperCase.indexOf(">", indexMeta);

                              // Strip meta tag text
                              return text.substring(0, indexMeta - 1) +
                              text.substring(indexHeadEnd + 1);
                              }
                              // </editor-fold>

                              }



                              Instead if you try

                              browser.getText()

                              You will get a NullPointerException

                              If you try
                                  public void setText(String text) {
                                      // Workaround for bug Bug ID: 4695909 in java 1.4
                                      // JEditorPane does not handle the META tag in the html HEAD
                                      if (isJava14() && "text/
                              html".equalsIgnoreCase(getContentType())) {
                                          text = stripMetaTag(text);
                                      }
                                      System.out.println(text); // YOU WILL SEE CNN'S HTML
                                      super.setText(text);
                                      System.out.println(super.getText()); // SEE BELOW
                                  }
                              You see only this:
                              <html>
                                <head>
                              
                                </head>
                                <body>
                                  <p style="margin-top: 0">
                              
                                  </p>
                                </body>
                              </html> 
                              • 12. Re: inconsistent ArrayIndexOutOfBoundsException using SwingWorker worker th
                                807599
                                I suspect that you need to "clean" your html prior to
                                calling super.setText(). My guess is that you're
                                yanking nodes from beaneath Swing while it's trying
                                to render.

                                In addition to that, you may want to use JTidy to
                                clean up your html, and convert it to xhtml -- again
                                prior to calling super.setText().
                                I can't use JTidy, the latest build I found on SourceForge is from 2001 and not only old but obsolete. Someone have a newer, cleaner build and know how to use it to show a moron like me?