jTidy returns nothing after tidying HTML <p>I have come across a very annoying problem when using jTidy (on Android). I have found jTidy works on every HTML Document I have tested it against, except the following:</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;!-- Always force latest IE rendering engine &amp; Chrome Frame Remove this if you use the .htaccess --&gt; &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /&gt; &lt;title&gt;templates&lt;/title&gt; &lt;meta name="description" content="" /&gt; &lt;meta name="author" content="" /&gt; &lt;meta name="viewport" content="width=device-width; initial-scale=1.0" /&gt; &lt;!-- Replace favicon.ico &amp; apple-touch-icon.png in the root of your domain and delete these references --&gt; &lt;link rel="shortcut icon" href="/favicon.ico" /&gt; &lt;link rel="apple-touch-icon" href="/apple-touch-icon.png" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;header&gt; &lt;h1&gt;Page Heading&lt;/h1&gt; &lt;/header&gt; &lt;nav&gt; &lt;p&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="/contact"&gt;Contact&lt;/a&gt;&lt;/p&gt; &lt;/nav&gt; &lt;div&gt; &lt;/div&gt; &lt;footer&gt; &lt;p&gt;&amp;copy; Copyright&lt;/p&gt; &lt;/footer&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>But after tidying it, jTidy returns nothing (as in, if the String containing the Tidied HTML is called result, result.equals("") == true)</p> <p>I have noticed something very interesting though: if I remove everything in the body part of the HTML jTidy works perfectly. Is there something in the &lt;body&gt;&lt;/body&gt; jTidy doesn't like?</p> <p>Here is the Java code I am using:</p> <pre><code> public String tidy(String sourceHTML) { StringReader reader = new StringReader(sourceHTML); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Tidy tidy = new Tidy(); tidy.setMakeClean(true); tidy.setQuiet(false); tidy.setIndentContent(true); tidy.setSmartIndent(true); tidy.parse(reader, baos); try { return baos.toString(mEncoding); } catch (UnsupportedEncodingException e) { return null; } } </code></pre> <p>Is there something wrong with my Java? Is this an error with jTidy? Is there any way I can make jTidy not do this? (I cannot change the HTML). If this absolutely cannot be fixed, are there any other good HTML Tidiers? Thanks very much!</p>