changeset 1209:40d37c2486a0

jnlp-signing mechanism now uses general parser (and so also tagsoup if enabled) * netx/net/sourceforge/jnlp/JNLPMatcher.java: removed redundant code to laod xmls and used Parser.getRootNode rather. Added same brackets to if statements. Added parameter of ParserSettings to * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: same. * tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java: refactored to autoclseable and to never use tagsoup. * tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTestMallformedAllowed.java: new file, copy of JNLPMatcherTest. But always using tagsoup (if available)
author Jiri Vanek <jvanek@redhat.com>
date Wed, 15 Apr 2015 10:43:53 +0200
parents 3a2bcf0e60d9
children 5837261a12aa
files ChangeLog netx/net/sourceforge/jnlp/JNLPMatcher.java netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTestMallformedAllowed.java tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java
diffstat 6 files changed, 559 insertions(+), 374 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Apr 15 10:36:09 2015 +0200
+++ b/ChangeLog	Wed Apr 15 10:43:53 2015 +0200
@@ -1,3 +1,15 @@
+2015-04-15  Jiri Vanek  <jvanek@redhat.com>
+
+	jnlp-signing mechanism now uses general parser (and so also tagsoup if enabled)
+	* netx/net/sourceforge/jnlp/JNLPMatcher.java: removed redundant code to laod xmls
+	and used Parser.getRootNode rather. Added same brackets to if statements. Added
+	parameter of ParserSettings to 
+	* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: same.
+	* tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java: refactored to
+	autoclseable and to never use tagsoup.
+	* tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTestMallformedAllowed.java:
+	new file, copy of JNLPMatcherTest. But always using tagsoup (if available)
+
 2015-04-15  Jiri Vanek  <jvanek@redhat.com>
 
 	KeystorePasswordAttempter moved to outer class. Added comments and prevention
--- a/netx/net/sourceforge/jnlp/JNLPMatcher.java	Wed Apr 15 10:36:09 2015 +0200
+++ b/netx/net/sourceforge/jnlp/JNLPMatcher.java	Wed Apr 15 10:43:53 2015 +0200
@@ -73,56 +73,30 @@
      *            the reader stream of the launching JNLP file
      * @param isTemplate
      *            a boolean that specifies if appTemplateFile is a template
+     * @param p settings of parser
      * @throws JNLPMatcherException
      *             if IOException, XMLParseException is thrown during parsing;
      *             Or launchJNLP/appTemplate is null
      */
-    public JNLPMatcher(Reader appTemplate, Reader launchJNLP,
-            boolean isTemplate) throws JNLPMatcherException {
+    public JNLPMatcher(InputStream appTemplate, InputStream launchJNLP,
+            boolean isTemplate, ParserSettings p) throws JNLPMatcherException {
 
         if (appTemplate == null && launchJNLP == null)
-            throw new JNLPMatcherException(
-                    "Template JNLP file and Launching JNLP file are both null.");
+            throw new JNLPMatcherException("Template JNLP file and Launching JNLP file are both null.");
         else if (appTemplate == null)
             throw new JNLPMatcherException("Template JNLP file is null.");
         else if (launchJNLP == null)
             throw new JNLPMatcherException("Launching JNLP file is null.");
-        
-        //Declare variables for signed JNLP file
-        ByteArrayOutputStream poutTemplate= null;
-      
-        //Declare variables for launching JNLP file 
-        ByteArrayOutputStream poutJNLPFile = null;
-        
+            
         try {
-            XMLElement appTemplateXML = new XMLElement();
-            XMLElement launchJNLPXML = new XMLElement();
-
-            // Remove the comments and CDATA from the JNLP file
-            poutTemplate = new ByteArrayOutputStream();
-            appTemplateXML.sanitizeInput(appTemplate, poutTemplate);
-
-            poutJNLPFile = new ByteArrayOutputStream();
-            launchJNLPXML.sanitizeInput(launchJNLP, poutJNLPFile);
-
-            // Parse both files
-            appTemplateXML.parseFromReader(new StringReader(poutTemplate.toString()));
-            launchJNLPXML.parseFromReader(new StringReader(poutJNLPFile.toString()));
-
-            // Initialize parent nodes
-            this.appTemplateNode = new Node(appTemplateXML);
-            this.launchJNLPNode = new Node(launchJNLPXML);
+            this.appTemplateNode = Parser.getRootNode(appTemplate, p);
+            this.launchJNLPNode = Parser.getRootNode(launchJNLP, p);
             this.isTemplate = isTemplate;
-
         } catch (Exception e) {
-            throw new JNLPMatcherException(
-                    "Failed to create an instance of JNLPVerify with specified InputStreamReader",
-                    e);
+            throw new JNLPMatcherException("Failed to create an instance of JNLPVerify with specified InputStreamReader", e);
         } finally {
-            // Close all stream
-            closeOutputStream(poutTemplate);
-            
-            closeOutputStream(poutJNLPFile);
+            closeInputStream(appTemplate);
+            closeInputStream(launchJNLP);
 
         }
     }
@@ -155,10 +129,8 @@
             Node templateNode = appTemplate;
             Node launchNode = launchJNLP;
             // Store children of Node
-            List<Node> appTemplateChild = new LinkedList<Node>(Arrays.asList(templateNode
-                    .getChildNodes()));
-            List<Node> launchJNLPChild = new LinkedList<Node>(Arrays.asList(launchNode
-                    .getChildNodes()));
+            List<Node> appTemplateChild = new LinkedList<>(Arrays.asList(templateNode.getChildNodes()));
+            List<Node> launchJNLPChild = new LinkedList<>(Arrays.asList(launchNode.getChildNodes()));
 
             // Compare only if both Nodes have the same name, else return false
             if (templateNode.getNodeName().equals(launchNode.getNodeName())) {
@@ -170,12 +142,10 @@
 
                     for (int i = 0; i < childLength;) {
                         for (int j = 0; j < childLength; j++) {
-                            boolean isSame = matchNodes(appTemplateChild.get(i),
-                                    launchJNLPChild.get(j));
-
-                            if (!isSame && j == childLength - 1)
+                            boolean isSame = matchNodes(appTemplateChild.get(i), launchJNLPChild.get(j));
+                            if (!isSame && j == childLength - 1) {
                                 return false;
-                            else if (isSame) { // If both child matches, remove them from the list of children
+                            } else if (isSame) { // If both child matches, remove them from the list of children
                                 appTemplateChild.remove(i);
                                 launchJNLPChild.remove(j);
                                 --childLength;
@@ -187,11 +157,13 @@
                     if (!templateNode.getNodeValue().equals(launchNode.getNodeValue())) {
 
                         // If it's a template and the template's value is NOT '*'
-                        if (isTemplate && !templateNode.getNodeValue().equals("*"))
+                        if (isTemplate && !templateNode.getNodeValue().equals("*")) {
                             return false;
+                        }
                         // Else if it's not a template, then return false
-                        else if (!isTemplate)
+                        else if (!isTemplate) {
                             return false;
+                        }
                     }
                     // Compare attributes of both Nodes
                     return matchAttributes(templateNode, launchNode);
@@ -233,15 +205,15 @@
                         boolean isSame = templateNode.getAttribute(attribute).equals( // Check if the Attribute values match
                                 launchNode.getAttribute(attribute));
 
-                        if (!isTemplate && !isSame)
+                        if (!isTemplate && !isSame) {
                             return false;
-                        else if (isTemplate && !isSame
-                                && !templateNode.getAttribute(attribute).equals("*"))
+                        } else if (isTemplate && !isSame && !templateNode.getAttribute(attribute).equals("*")) {
                             return false;
-
-                    } else
+                        }
+                    } else {
                         // If attributes names do not match, return false
                         return false;
+                    }
                 }
                 return true;
             }
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Wed Apr 15 10:36:09 2015 +0200
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Wed Apr 15 10:43:53 2015 +0200
@@ -18,11 +18,10 @@
 import static net.sourceforge.jnlp.runtime.Translator.R;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.net.MalformedURLException;
 import java.net.SocketPermission;
 import java.net.URL;
@@ -967,12 +966,6 @@
         List<JARDesc> desc = new ArrayList<>();
         desc.add(jarDesc);
 
-        // Initialize streams
-        InputStream inStream = null;
-        InputStreamReader inputReader = null;
-        FileReader fr = null;
-        InputStreamReader jnlpReader = null;
-
         try {
             // NOTE: verification should have happened by now. In other words,
             // calling jcv.verifyJars(desc, tracker) here should have no affect.
@@ -982,41 +975,27 @@
                     String jeName = je.getName().toUpperCase();
 
                     if (jeName.equals(TEMPLATE) || jeName.equals(APPLICATION)) {
-
                         OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Creating Jar InputStream from JarEntry");
-
-                        inStream = jarFile.getInputStream(je);
-                        inputReader = new InputStreamReader(inStream);
-
+                        InputStream inStream = jarFile.getInputStream(je);
                         OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Creating File InputStream from lauching JNLP file");
-
                         JNLPFile jnlp = this.getJNLPFile();
-                        URL url = jnlp.getFileLocation();
-                        File jn = null;
+                        File jn;
+                        // If the file is on the local file system, use original path, otherwise find cached file
+                        if (jnlp.getFileLocation().getProtocol().toLowerCase().equals("file")) {
+                            jn = new File(jnlp.getFileLocation().getPath());
+                        } else {
+                            jn = CacheUtil.getCacheFile(jnlp.getFileLocation(), null);
+                        }
 
-                        // If the file is on the local file system, use original path, otherwise find cached file
-                        if (url.getProtocol().toLowerCase().equals("file"))
-                            jn = new File(url.getPath());
-                        else
-                            jn = CacheUtil.getCacheFile(url, null);
-
-                        fr = new FileReader(jn);
-                        jnlpReader = fr;
-
-                        // Initialize JNLPMatcher class
+                        InputStream jnlpStream = new FileInputStream(jn);
                         JNLPMatcher matcher;
-
                         if (jeName.equals(APPLICATION)) { // If signed application was found
                             OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "APPLICATION.JNLP has been located within signed JAR. Starting verfication...");
-                           
-                            matcher = new JNLPMatcher(inputReader, jnlpReader, false);
+                            matcher = new JNLPMatcher(inStream, jnlpStream, false, jnlp.getParserSettings());
                         } else { // Otherwise template was found
                             OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "APPLICATION_TEMPLATE.JNLP has been located within signed JAR. Starting verfication...");
-                            
-                            matcher = new JNLPMatcher(inputReader, jnlpReader,
-                                    true);
+                            matcher = new JNLPMatcher(inStream, jnlpStream, true, jnlp.getParserSettings());
                         }
-
                         // If signed JNLP file does not matches launching JNLP file, throw JNLPMatcherException
                         if (!matcher.isMatch())
                             throw new JNLPMatcherException("Signed Application did not match launching JNLP File");
@@ -1054,15 +1033,7 @@
              * skip the check for a signed JNLP file
              */
             
-        } finally {
-
-            //Close all streams
-            StreamUtils.closeSilently(inStream);
-            StreamUtils.closeSilently(inputReader);
-            StreamUtils.closeSilently(fr);
-            StreamUtils.closeSilently(jnlpReader);
         }
-
         OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Ending check for signed JNLP file...");
     }
 
--- a/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java	Wed Apr 15 10:36:09 2015 +0200
+++ b/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java	Wed Apr 15 10:43:53 2015 +0200
@@ -37,19 +37,18 @@
 
 package net.sourceforge.jnlp;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
 import java.util.Random;
 import net.sourceforge.jnlp.annotations.KnownToFail;
-
 import org.junit.Assert;
 import org.junit.Test;
 
 public class JNLPMatcherTest {
 
-    final String tests[] = {
+    static final String tests[] = {
             "Testing template with CDATA",
             "Testing template with an exact duplicate of the launching JNLP file",
             "Testing template with wildchars as attribute/element values",
@@ -71,320 +70,192 @@
             "Testing application with a complete different JNLP application file",
             "Testing by calling JNLPMatcher.match() multiple times. Checking to see if the returns value is consistent" };
 
-    final ClassLoader cl = ClassLoader.getSystemClassLoader();
+    private final ClassLoader cl = ClassLoader.getSystemClassLoader();
+    private final boolean MALLFORMED_ALLOWED = false;
 
-    private InputStreamReader getLaunchReader() {
-        InputStream launchStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/launchApp.jnlp");
-        return new InputStreamReader(launchStream);
+    private InputStream getLaunchReader() {
+        return cl.getResourceAsStream("net/sourceforge/jnlp/launchApp.jnlp");
     }
 
     @Test
     @KnownToFail
     public void testTemplateCDATA() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template0.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[0], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template0.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+             Assert.assertEquals(tests[0], true, test.isMatch());
+        }
     }
 
     @Test
     public void testTemplateDuplicate() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template1.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[1], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template1.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[1], true, test.isMatch());
+        }
     }
 
     @Test
     public void testTemplateWildCharsRandom() throws JNLPMatcherException, IOException {
 
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template2.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[2], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template2.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[2], true, test.isMatch());
+        }
     }
 
     @Test
     public void testTemplateDifferentOrder() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template3.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[3], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template3.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[3], true, test.isMatch());
+        }
     }
 
     @Test
     public void testTemplateWildCharsAsAllValues() throws JNLPMatcherException,
             IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template4.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[4], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template4.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[4], true, test.isMatch());
+        }
     }
 
     @Test
     public void testTemplateComments() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template5.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[5], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        //heving comment inside element declaration is invalid but internal parser can handle it
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template5.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[5], true, test.isMatch());
+        }
     }
 
     @Test
     public void testTemplateDifferentValues() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template6.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[6], false, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template6.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[6], false, test.isMatch());
+        }
     }
 
     @Test
     public void testTemplateExtraChild() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template7.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[7], false, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template7.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[7], false, test.isMatch());
+        }
     }
 
     @Test
     public void testTemplateFewerChild() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template8.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[8], false, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template8.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[8], false, test.isMatch());
+        }
     }
 
     @Test
     public void testTemplateDifferentFile() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/templates/template9.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, true);
-
-        Assert.assertEquals(tests[9], false, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template9.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[9], false, test.isMatch());
+        }
     }
 
     @Test
     @KnownToFail
     public void testApplicationCDATA() throws JNLPMatcherException, IOException {
 
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application0.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
-
-        Assert.assertEquals(tests[10], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application0.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[10], true, test.isMatch());
+        }
     }
 
     @Test
     public void testApplicationDuplicate() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application1.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
-
-        Assert.assertEquals(tests[11], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application1.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[11], true, test.isMatch());
+        }
     }
 
     @Test
     public void testApplicationDifferentOrder() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application2.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
-
-        Assert.assertEquals(tests[12], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application2.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[12], true, test.isMatch());
+        }
     }
 
     @Test
     public void testApplicationComments() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application3.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
-
-        Assert.assertEquals(tests[13], true, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application3.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[13], true, test.isMatch());
+        }
     }
 
     @Test
     public void testApplicationWildCharsRandom() throws JNLPMatcherException, IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application4.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
-
-        Assert.assertEquals(tests[14], false, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application4.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[14], false, test.isMatch());
+        }
     }
 
     @Test
     public void testApplicationDifferentCodebaseValue() throws JNLPMatcherException,
             IOException {
-
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application5.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
-
-        Assert.assertEquals(tests[15], false, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application5.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[15], false, test.isMatch());
+        }
     }
 
     @Test
     public void testApplicationExtraChild() throws JNLPMatcherException, IOException {
 
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application6.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
-
-        Assert.assertEquals(tests[16], false, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application6.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[16], false, test.isMatch());
+        }
     }
 
     @Test
     public void testApplicationFewerChild() throws JNLPMatcherException, IOException {
 
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application7.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
-
-        Assert.assertEquals(tests[17], false, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application7.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[17], false, test.isMatch());
+        }
     }
 
     @Test
     public void testApplicationDifferentFile() throws JNLPMatcherException, IOException {
 
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application8.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
-
-        Assert.assertEquals(tests[18], false, test.isMatch());
-        fileReader.close();
-        launchReader.close();
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application8.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[18], false, test.isMatch());
+        }
     }
 
     @SuppressWarnings("unused")
@@ -392,62 +263,56 @@
     public void testNullJNLPFiles() throws IOException {
 
         Exception expectedException = null;
-        InputStreamReader launchReader = this.getLaunchReader();
-
-        InputStream fileStream = cl
-                .getResourceAsStream("net/sourceforge/jnlp/application/application8.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
-
-        try {
-            JNLPMatcher test = new JNLPMatcher(null, launchReader, false);
-        } catch (Exception e) {
-            expectedException = e;
-        }
-        Assert.assertEquals(
-                "Checking exception after trying to create an instance with null signed application/template reader",
-                expectedException.getClass().getName(),
-                "net.sourceforge.jnlp.JNLPMatcherException");
-
-        try {
-            JNLPMatcher test = new JNLPMatcher(fileReader, null, false);
-        } catch (Exception e) {
-            expectedException = e;
-        }
-        Assert.assertEquals(
-                "Checking exception after trying to create an instance with null launching JNLP file reader",
-                expectedException.getClass().getName(),
-                "net.sourceforge.jnlp.JNLPMatcherException");
-
-        try {
-            JNLPMatcher test = new JNLPMatcher(null, null, false);
-        } catch (Exception e) {
-            expectedException = e;
-        }
-        Assert.assertEquals(
-                "Checking exception after trying to create an instance with both readers being null",
-                expectedException.getClass().getName(),
-                "net.sourceforge.jnlp.JNLPMatcherException");
-
-        launchReader.close();
-        fileReader.close();
+        InputStream fileStream;
+        try (InputStream launchReader = this.getLaunchReader()) {
+            fileStream = cl
+                    .getResourceAsStream("net/sourceforge/jnlp/application/application8.jnlp");
+            try {
+                JNLPMatcher test = new JNLPMatcher(null, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            } catch (Exception e) {
+                expectedException = e;
+            }
+            Assert.assertEquals(
+                    "Checking exception after trying to create an instance with null signed application/template reader",
+                    expectedException.getClass().getName(),
+                    "net.sourceforge.jnlp.JNLPMatcherException");
+            try {
+                JNLPMatcher test = new JNLPMatcher(fileStream, null, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            } catch (Exception e) {
+                expectedException = e;
+            }
+            Assert.assertEquals(
+                    "Checking exception after trying to create an instance with null launching JNLP file reader",
+                    expectedException.getClass().getName(),
+                    "net.sourceforge.jnlp.JNLPMatcherException");
+            try {
+                JNLPMatcher test = new JNLPMatcher(null, null, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            } catch (Exception e) {
+                expectedException = e;
+            }
+            Assert.assertEquals(
+                    "Checking exception after trying to create an instance with both readers being null",
+                    expectedException.getClass().getName(),
+                    "net.sourceforge.jnlp.JNLPMatcherException");
+        }        fileStream.close();
     }
 
     @Test
     public void testCallingMatchMultiple() throws JNLPMatcherException, IOException {
 
         // Check with application
-        InputStreamReader launchReader = this.getLaunchReader();
+        InputStream launchReader = this.getLaunchReader();
 
         InputStream fileStream = cl
                 .getResourceAsStream("net/sourceforge/jnlp/application/application8.jnlp");
-        InputStreamReader fileReader = new InputStreamReader(fileStream);
+        
 
-        JNLPMatcher test = new JNLPMatcher(fileReader, launchReader, false);
+        JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
 
         Assert.assertEquals(tests[19], false, test.isMatch());
         Assert.assertEquals(tests[19], false, test.isMatch());
 
-        fileReader.close();
+        fileStream.close();
         launchReader.close();
 
         // Check with template
@@ -455,19 +320,18 @@
 
         fileStream = cl
                 .getResourceAsStream("net/sourceforge/jnlp/templates/template6.jnlp");
-        fileReader = new InputStreamReader(fileStream);
 
-        test = new JNLPMatcher(fileReader, launchReader, true);
+        test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
 
         Assert.assertEquals(tests[19], false, test.isMatch());
         Assert.assertEquals(tests[19], false, test.isMatch());
 
-        fileReader.close();
+        fileStream.close();
         launchReader.close();
     }
 
     @Test (timeout=5000 /*ms*/)
-    public void testIsMatchDoesNotHangOnLargeData() throws JNLPMatcherException {
+    public void testIsMatchDoesNotHangOnLargeData() throws JNLPMatcherException, UnsupportedEncodingException {
         /* construct an alphabet containing characters 'a' to 'z' */
         final int ALPHABET_SIZE = 26;
         char[] alphabet = new char[ALPHABET_SIZE];
@@ -492,9 +356,9 @@
                 "  </information>\n" +
                 "</jnlp>\n";
 
-        StringReader reader1 = new StringReader(file);
-        StringReader reader2 = new StringReader(file);
-        JNLPMatcher matcher = new JNLPMatcher(reader1, reader2, false);
+        InputStream reader1 = new ByteArrayInputStream(file.getBytes("utf-8"));
+        InputStream reader2 = new ByteArrayInputStream(file.getBytes("utf-8"));
+        JNLPMatcher matcher = new JNLPMatcher(reader1, reader2, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
         Assert.assertTrue(matcher.isMatch());
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTestMallformedAllowed.java	Wed Apr 15 10:43:53 2015 +0200
@@ -0,0 +1,340 @@
+/* JNLPMatcherTest.java
+   Copyright (C) 2011 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+package net.sourceforge.jnlp;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Random;
+import net.sourceforge.jnlp.annotations.KnownToFail;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JNLPMatcherTestMallformedAllowed {
+
+    final String tests[] = JNLPMatcherTest.tests;
+
+    private final ClassLoader cl = ClassLoader.getSystemClassLoader();
+    private final boolean MALLFORMED_ALLOWED = true;
+
+    private InputStream getLaunchReader() {
+        return cl.getResourceAsStream("net/sourceforge/jnlp/launchApp.jnlp");
+    }
+
+    @Test
+    @KnownToFail
+    public void testTemplateCDATA() throws JNLPMatcherException, IOException {
+
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template0.jnlp")) {
+
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+             Assert.assertEquals(tests[0], true, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testTemplateDuplicate() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template1.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[1], true, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testTemplateWildCharsRandom() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template2.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[2], true, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testTemplateDifferentOrder() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template3.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[3], true, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testTemplateWildCharsAsAllValues() throws JNLPMatcherException,
+            IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template4.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[4], true, test.isMatch());
+        }
+    }
+
+    @Test
+    @KnownToFail
+    public void testTemplateComments() throws JNLPMatcherException, IOException {
+    //heving comment inside element declaration is invalid anyway, so tagsoup can be excused for failing in this case
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template5.jnlp")) {
+                       JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[5], true, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testTemplateDifferentValues() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template6.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[6], false, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testTemplateExtraChild() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template7.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[7], false, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testTemplateFewerChild() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template8.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[8], false, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testTemplateDifferentFile() throws JNLPMatcherException, IOException {
+
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template9.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[9], false, test.isMatch());
+        }
+    }
+
+    @Test
+    @KnownToFail
+    public void testApplicationCDATA() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application0.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[10], true, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testApplicationDuplicate() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application1.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[11], true, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testApplicationDifferentOrder() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application2.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[12], true, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testApplicationComments() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application3.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[13], true, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testApplicationWildCharsRandom() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application4.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[14], false, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testApplicationDifferentCodebaseValue() throws JNLPMatcherException,
+            IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application5.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[15], false, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testApplicationExtraChild() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application6.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[16], false, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testApplicationFewerChild() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application7.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[17], false, test.isMatch());
+        }
+    }
+
+    @Test
+    public void testApplicationDifferentFile() throws JNLPMatcherException, IOException {
+        try (InputStream launchReader = this.getLaunchReader(); InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application8.jnlp")) {
+            JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            Assert.assertEquals(tests[18], false, test.isMatch());
+        }
+    }
+
+    @SuppressWarnings("unused")
+    @Test
+    public void testNullJNLPFiles() throws IOException {
+
+        Exception expectedException = null;
+        InputStream fileStream;
+        try (InputStream launchReader = this.getLaunchReader()) {
+            fileStream = cl
+                    .getResourceAsStream("net/sourceforge/jnlp/application/application8.jnlp");
+            try {
+                JNLPMatcher test = new JNLPMatcher(null, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            } catch (Exception e) {
+                expectedException = e;
+            }
+            Assert.assertEquals(
+                    "Checking exception after trying to create an instance with null signed application/template reader",
+                    expectedException.getClass().getName(),
+                    "net.sourceforge.jnlp.JNLPMatcherException");
+            try {
+                JNLPMatcher test = new JNLPMatcher(fileStream, null, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            } catch (Exception e) {
+                expectedException = e;
+            }
+            Assert.assertEquals(
+                    "Checking exception after trying to create an instance with null launching JNLP file reader",
+                    expectedException.getClass().getName(),
+                    "net.sourceforge.jnlp.JNLPMatcherException");
+            try {
+                JNLPMatcher test = new JNLPMatcher(null, null, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+            } catch (Exception e) {
+                expectedException = e;
+            }
+            Assert.assertEquals(
+                    "Checking exception after trying to create an instance with both readers being null",
+                    expectedException.getClass().getName(),
+                    "net.sourceforge.jnlp.JNLPMatcherException");
+        }        fileStream.close();
+    }
+
+    @Test
+    public void testCallingMatchMultiple() throws JNLPMatcherException, IOException {
+        // Check with application
+        InputStream launchReader = this.getLaunchReader();
+        InputStream fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/application/application8.jnlp");
+        
+        JNLPMatcher test = new JNLPMatcher(fileStream, launchReader, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+
+        Assert.assertEquals(tests[19], false, test.isMatch());
+        Assert.assertEquals(tests[19], false, test.isMatch());
+
+        fileStream.close();
+        launchReader.close();
+
+        // Check with template
+        launchReader = this.getLaunchReader();
+
+        fileStream = cl
+                .getResourceAsStream("net/sourceforge/jnlp/templates/template6.jnlp");
+
+        test = new JNLPMatcher(fileStream, launchReader, true, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+
+        Assert.assertEquals(tests[19], false, test.isMatch());
+        Assert.assertEquals(tests[19], false, test.isMatch());
+
+        fileStream.close();
+        launchReader.close();
+    }
+
+    @Test (timeout=5000 /*ms*/)
+    public void testIsMatchDoesNotHangOnLargeData() throws JNLPMatcherException, UnsupportedEncodingException {
+        /* construct an alphabet containing characters 'a' to 'z' */
+        final int ALPHABET_SIZE = 26;
+        char[] alphabet = new char[ALPHABET_SIZE];
+        for (int i = 0; i < ALPHABET_SIZE; i++) {
+            alphabet[i] = (char)('a' + i);
+        }
+        /* generate a long but random string using the alphabet */
+        final Random r = new Random();
+        final int STRING_SIZE = 1024 * 1024; // 1 MB
+        StringBuilder descriptionBuilder = new StringBuilder(STRING_SIZE);
+        for (int i = 0; i < STRING_SIZE; i++) {
+            descriptionBuilder.append(alphabet[r.nextInt(ALPHABET_SIZE)]);
+        }
+        String longDescription = descriptionBuilder.toString();
+
+        String file =
+                "<jnlp>\n" +
+                "  <information>\n" +
+                "    <title>JNLPMatcher hanges on large file size</title>\n" +
+                "    <vendor>IcedTea</vendor>\n" +
+                "    <description>" + longDescription + "</description>\n" +
+                "  </information>\n" +
+                "</jnlp>\n";
+
+        InputStream reader1 = new ByteArrayInputStream(file.getBytes("utf-8"));
+        InputStream reader2 = new ByteArrayInputStream(file.getBytes("utf-8"));
+        JNLPMatcher matcher = new JNLPMatcher(reader1, reader2, false, new ParserSettings(true, true, MALLFORMED_ALLOWED));
+        Assert.assertTrue(matcher.isMatch());
+    }
+}
--- a/tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java	Wed Apr 15 10:36:09 2015 +0200
+++ b/tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java	Wed Apr 15 10:43:53 2015 +0200
@@ -39,6 +39,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.StringReader;
 import net.sourceforge.jnlp.annotations.KnownToFail;
 
@@ -208,4 +209,29 @@
         //defaultis used
         Assert.assertEquals("1.0+", p.getSpecVersion().toString());
     }
+    
+    @Test
+    public void testCommentInElements3_malformedOff() throws JNLPMatcherException, IOException, ParseException {
+        //heving comment inside element declaration is invalid but internal parser can handle it
+         try (InputStream fileStream = ClassLoader.getSystemClassLoader()
+                 .getResourceAsStream("net/sourceforge/jnlp/templates/template5.jnlp")) {
+             Node root = Parser.getRootNode(fileStream, new ParserSettings(false, true, false));
+             String a = root.getChildNodes()[2].getAttribute("main-class");
+             Assert.assertEquals("*", a);
+
+        }
+    }
+    
+      @Test
+      @KnownToFail
+    public void testCommentInElements3_malformedOn() throws JNLPMatcherException, IOException, ParseException {
+        //heving comment inside element declaration is invalid anyway, so tagsoup can be excused for failing in this case
+         try (InputStream fileStream = ClassLoader.getSystemClassLoader()
+                 .getResourceAsStream("net/sourceforge/jnlp/templates/template5.jnlp")) {
+             Node root = Parser.getRootNode(fileStream, new ParserSettings(false, true, true));
+             String a = root.getChildNodes()[2].getAttribute("main-class");
+             Assert.assertEquals("*", a);
+
+        }
+    }
 }