Skip to content

Commit

Permalink
[FIXED JENKINS-17402] getItem may return null but may not throw IAE.(…
Browse files Browse the repository at this point in the history
…cherry picked from commit 7fa8fe4)

Conflicts:
	changelog.html
  • Loading branch information
jglick authored and vjuranek committed May 17, 2013
1 parent 83b5ccb commit 01f09f6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion changelog.html
Expand Up @@ -55,7 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class='major bug'>
NPE configuring Copy Artifact with Maven jobs.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17402">issue 17402</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/model/ItemGroup.java
Expand Up @@ -26,6 +26,7 @@
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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java
Expand Up @@ -432,7 +432,11 @@ public Collection<MavenModule> getModules() {
}

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) {
Expand Down
7 changes: 7 additions & 0 deletions test/src/test/java/hudson/maven/MavenModuleSetTest.java
Expand Up @@ -2,6 +2,7 @@

import hudson.maven.local_repo.PerJobLocalRepositoryLocator;
import hudson.model.Item;
import org.jvnet.hudson.test.Bug;

import org.jvnet.hudson.test.HudsonTestCase;

Expand All @@ -22,4 +23,10 @@ public void testConfigRoundtripLocalRepository() throws Exception {
assertEqualDataBoundBeans(p.getLocalRepository(),before);
assertTrue(before!=p.getLocalRepository());
}

@Bug(17402)
public void testGetItem() throws Exception {
assertNull(createMavenProject().getItem("invalid"));
}

}

0 comments on commit 01f09f6

Please sign in to comment.