提交 7fa8fe40 编写于 作者: J Jesse Glick

[FIXED JENKINS-17402] getItem may return null but may not throw IAE.

上级 40574632
......@@ -63,6 +63,9 @@ Upcoming changes</a>
<li class=bug>
NPE from <code>MatrixConfiguration.newBuild</code>.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17728">issue 17728</a>)
<li class='major bug'>
NPE configuring Copy Artifact with Maven jobs.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17402">issue 17402</a>)
<li class=rfe>
<code>/about</code> now links to license information for plugins as well.
<li class=rfe>
......
......@@ -26,6 +26,7 @@ package hudson.model;
import java.io.IOException;
import java.util.Collection;
import java.io.File;
import javax.annotation.CheckForNull;
/**
* Represents a grouping inherent to a kind of {@link Item}s.
......@@ -64,9 +65,9 @@ public interface ItemGroup<T extends Item> extends PersistenceRoot, ModelObject
String getUrlChildPrefix();
/**
* Gets the {@link Item} inside this group that has a given name.
* Gets the {@link Item} inside this group that has a given name, or null if it does not exist.
*/
T getItem(String name);
@CheckForNull T getItem(String name);
/**
* Assigns the {@link Item#getRootDir() root directory} for children.
......
......@@ -434,7 +434,11 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
}
public MavenModule getItem(String name) {
return modules.get(ModuleName.fromString(name));
try {
return modules.get(ModuleName.fromString(name));
} catch (IllegalArgumentException x) {
return null; // not a Maven module name, ignore
}
}
public MavenModule getModule(String name) {
......
......@@ -2,6 +2,7 @@ package hudson.maven;
import hudson.maven.local_repo.PerJobLocalRepositoryLocator;
import hudson.model.Item;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
......@@ -22,4 +23,10 @@ public class MavenModuleSetTest extends HudsonTestCase {
assertEqualDataBoundBeans(p.getLocalRepository(),before);
assertTrue(before!=p.getLocalRepository());
}
@Bug(17402)
public void testGetItem() throws Exception {
assertNull(createMavenProject().getItem("invalid"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册