424051 - Using --list-config can result in NPE

+ Adding protection for no-manifest
+ Adding bad-jar tests for no-manifest, not-a-jar, and zero-length
This commit is contained in:
Joakim Erdfelt 2013-12-14 18:03:19 -07:00
parent 41fc2b8f87
commit 8bf4a4f263
5 changed files with 60 additions and 1 deletions

View File

@ -149,6 +149,11 @@ public class JarVersion
Manifest manifest = jar.getManifest(); Manifest manifest = jar.getManifest();
if (manifest == null)
{
return "(none specified)";
}
version = getMainManifestImplVersion(manifest); version = getMainManifestImplVersion(manifest);
if (version != null) if (version != null)
{ {
@ -173,7 +178,7 @@ public class JarVersion
return version; return version;
} }
return "(not specified)"; return "(none specified)";
} }
catch (IOException e) catch (IOException e)
{ {

View File

@ -0,0 +1,54 @@
//
// ========================================================================
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.start;
import static org.hamcrest.Matchers.*;
import java.io.File;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.Assert;
import org.junit.Test;
public class JarVersionTest
{
private void assertJarVersion(String jarname, String expectedVersion)
{
File jarfile = MavenTestingUtils.getTestResourceFile(jarname);
Assert.assertThat("Jar: " + jarname,JarVersion.getVersion(jarfile),containsString(expectedVersion));
}
@Test
public void testNoManifestJar()
{
assertJarVersion("bad-libs/no-manifest.jar","(none specified)");
}
@Test
public void testNotAJar()
{
assertJarVersion("bad-libs/not-a.jar","(error: ZipException ");
}
@Test
public void testZeroLengthJar()
{
assertJarVersion("bad-libs/zero-length.jar","(error: ZipException ");
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB