Skip to content
Permalink
Browse files
[JENKINS-12307] More helpful error message for getItemTypeDescriptorO…
…rDie on a non-collection field.
  • Loading branch information
jglick committed Oct 15, 2012
1 parent cb53486 commit dcea7d5bf6a011518bbc642426d26073b337086a
Showing with 57 additions and 0 deletions.
  1. +3 −0 core/src/main/java/hudson/model/Descriptor.java
  2. +54 −0 test/src/test/java/hudson/model/DescriptorTest.java
@@ -193,6 +193,9 @@ public Descriptor getItemTypeDescriptor() {

public Descriptor getItemTypeDescriptorOrDie() {
Class it = getItemType();
if (it == null) {
throw new AssertionError(clazz + " is not an array/collection type in " + displayName + ". See https://wiki.jenkins-ci.org/display/JENKINS/My+class+is+missing+descriptor");
}
Descriptor d = Jenkins.getInstance().getDescriptor(it);
if (d==null)
throw new AssertionError(it +" is missing its descriptor in "+displayName+". See https://wiki.jenkins-ci.org/display/JENKINS/My+class+is+missing+descriptor");
@@ -0,0 +1,54 @@
/*
* The MIT License
*
* Copyright 2012 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model;

import hudson.model.Descriptor.PropertyType;
import hudson.tasks.Shell;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;

public class DescriptorTest {

public @Rule JenkinsRule rule = new JenkinsRule();

@Bug(12307)
@Test public void getItemTypeDescriptorOrDie() throws Exception {
Describable<?> instance = new Shell("echo hello");
Descriptor<?> descriptor = instance.getDescriptor();
PropertyType propertyType = descriptor.getPropertyType(instance, "command");
try {
propertyType.getItemTypeDescriptorOrDie();
fail("not supposed to succeed");
} catch (AssertionError x) {
for (String text : new String[] {"hudson.tasks.CommandInterpreter", "getCommand", "java.lang.String", "collection"}) {
assertTrue(text + " mentioned in " + x, x.toString().contains(text));
}
}
}

}

0 comments on commit dcea7d5

Please sign in to comment.