package org.apache.markt.leaks.xml;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.markt.leaks.LeakBase;
import org.w3c.dom.Document;

/**
 * Java 5
 *   - TBD
 * Java 6
 *   - TBD
 * Java 7
 *   - TBD
 * Java 8
 *   - TBD
 */
public class NewDocumentLeak extends LeakBase {

    public static void main(String[] args) {
        NewDocumentLeak newDocumentLeak = new NewDocumentLeak();
        newDocumentLeak.doLeakTest();
    }


    @Override
    protected void createLeakingObjects() {
        // Nov/Dec 2009. 6.0.x - r892620 6.0.21
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder documentBuilder = factory.newDocumentBuilder();
            Document document = documentBuilder.newDocument();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }
    }


    @Override
    protected void cleanUpLeakingObjects() {
        // None
    }
}
@@ -70,16 +70,23 @@
 tBuilder
+Factory
 ;%0Aimport
@@ -90,178 +90,591 @@
 ort 
-javax.xml.parsers.DocumentBuilderFactory;%0Aimport javax.xml.parsers.ParserConfigurationException;%0A%0Aimport org.apache.markt.leaks.LeakBase;%0Aimport org.w3c.dom.Document;%0A%0A/*
+org.apache.markt.leaks.LeakBase;%0Aimport org.w3c.dom.Document;%0Aimport org.w3c.dom.ls.DOMImplementationLS;%0A%0A/**%0A * The new document leak is fixed in Java 7 onwards:%0A * http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6916498%0A *%0A * The Serializer and Normalizer leaks are very odd. Run the code in a Servlet%0A * and a memory leak occurs. Run it in this stand-along test harness and no leak%0A * occurs. Further, the GC roots for these leaks are not visible to the%0A * profiler.%0A * https://bz.apache.org/bugzilla/show_bug.cgi?id=58486%0A * https://bugs.openjdk.java.net/browse/JDK-8146961%0A 
 *%0A *
@@ -680,35 +680,37 @@
 * Java 5%0A *   - 
-TBD
+leaks
 %0A * Java 6%0A *   
@@ -703,35 +703,37 @@
 * Java 6%0A *   - 
-TBD
+leaks
 %0A * Java 7%0A *   
@@ -734,19 +734,21 @@
 %0A *   - 
-TBD
+leaks
 %0A * Java
@@ -761,11 +761,13 @@
   - 
-TBD
+leaks
 %0A */
@@ -1042,140 +1042,144 @@
     
-// Nov/Dec 2009. 6.0.x - r892620 6.0.21%0A        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();%0A        try %7B
+try %7B%0A            Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();%0A            // Serializer
 %0A   
@@ -1191,123 +1191,290 @@
     
-D
+d
 ocument
-Builder documentBuilder = factory.newDocumentBuilder();%0A            Document document = documentBuilder.new
+.createElement(%22test%22);%0A            DOMImplementationLS implementation = (DOMImplementationLS)document.getImplementation();%0A            implementation.createLSSerializer().writeToString(document);%0A            // or%0A            // Normalizer%0A            // document.normalize
 Docu
@@ -1473,32 +1473,33 @@
 lizeDocument();%0A
+%0A
         %7D catch 
@@ -1503,27 +1503,8 @@
 ch (
-ParserConfiguration
 Exce

Add more background