diff options
author | Jiri Vanek <[email protected]> | 2013-11-27 14:11:13 +0100 |
---|---|---|
committer | Jiri Vanek <[email protected]> | 2013-11-27 14:11:13 +0100 |
commit | 59233334144dca83fb017795d54d99636cccee81 (patch) | |
tree | a28c68f6af5745527ecd66e3620a440764ca2115 /tests/netx | |
parent | b8da03fd7a7aac183acebf7ccd26196ccafca9bc (diff) |
Added null check when getting manifest attributes for case of jar without manifest
* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: (getManifestAttribute) added check fo null manifest to prevent npe.
* /tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java: added test for npe from getManifestAttribute
* tests/test-extensions/net/sourceforge/jnlp/util/FileTestUtils.java: (createJarWithContents) enhanced to be able to create jar without manifest.
Diffstat (limited to 'tests/netx')
-rw-r--r-- | tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java b/tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java index e713512..26de7b6 100644 --- a/tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java +++ b/tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java @@ -51,6 +51,7 @@ import net.sourceforge.jnlp.cache.UpdatePolicy; import net.sourceforge.jnlp.mock.DummyJNLPFileWithJar; import net.sourceforge.jnlp.util.FileTestUtils; import net.sourceforge.jnlp.util.logging.NoStdOutErrTest; +import org.junit.Assert; import org.junit.Test; @@ -259,4 +260,38 @@ public class JNLPClassLoaderTest extends NoStdOutErrTest{ } }); } + + + @Test + public void tryNullManifest() throws Exception { + File tempDirectory = FileTestUtils.createTempDirectory(); + File jarLocation = new File(tempDirectory, "test-npe.jar"); + File dummyContent = File.createTempFile("dummy", "context", tempDirectory); + jarLocation.deleteOnExit(); + + /* Test with-out any attribute specified specified */ + FileTestUtils.createJarWithoutManifestContents(jarLocation, dummyContent); + + final Exception[] exs = new Exception[2]; + final DummyJNLPFileWithJar jnlpFile = new DummyJNLPFileWithJar(jarLocation); + try { + final JNLPClassLoader classLoader = new JNLPClassLoader(jnlpFile, UpdatePolicy.ALWAYS); + assertNoFileLeak(new Runnable() { + @Override + public void run() { + try { + assertEquals(null, classLoader.getManifestAttribute(jnlpFile.getJarLocation(), Attributes.Name.MAIN_CLASS)); + assertEquals(null, classLoader.getManifestAttribute(jnlpFile.getJarLocation(), Attributes.Name.IMPLEMENTATION_TITLE)); + } catch (Exception e) { + exs[0] = e; + } + } + }); + } catch (Exception e) { + exs[1] = e; + } + Assert.assertNotNull(exs); + Assert.assertNull(exs[0]); + Assert.assertNull(exs[1]); + } } |