提交 cac3efd9 编写于 作者: J Jesse Glick

Produce a helpful error message if optionalProperty#field is bogus.

Otherwise get a useless “null is missing its descriptor” from Jenkins.getDescriptorOrDie.
上级 871abe5f
......@@ -31,7 +31,6 @@ import hudson.BulkChange;
import hudson.Util;
import hudson.model.listeners.SaveableListener;
import hudson.util.FormApply;
import hudson.util.QuotedStringTokenizer;
import hudson.util.ReflectionUtils;
import hudson.util.ReflectionUtils.Parameter;
import hudson.views.ListViewColumn;
......@@ -72,6 +71,8 @@ import java.lang.reflect.Type;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.beans.Introspector;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
/**
* Metadata about a configurable instance.
......@@ -470,11 +471,27 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
/**
* Used by Jelly to abstract away the handlign of global.jelly vs config.jelly databinding difference.
*/
public PropertyType getPropertyType(Object instance, String field) {
public @CheckForNull PropertyType getPropertyType(@Nonnull Object instance, @Nonnull String field) {
// in global.jelly, instance==descriptor
return instance==this ? getGlobalPropertyType(field) : getPropertyType(field);
}
/**
* Akin to {@link #getPropertyType(Object,String) but never returns null.
* @throws AssertionError in case the field cannot be found
* @since 1.492
*/
public @Nonnull PropertyType getPropertyTypeOrDie(@Nonnull Object instance, @Nonnull String field) {
PropertyType propertyType = getPropertyType(instance, field);
if (propertyType != null) {
return propertyType;
} else if (instance == this) {
throw new AssertionError(getClass().getName() + " has no property " + field);
} else {
throw new AssertionError(clazz.getName() + " has no property " + field);
}
}
/**
* Obtains the property type of the given field of {@link #clazz}
*/
......
......@@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<st:documentation>
Renders inline an optional single-value nested data-bound property of the current instance,
......@@ -39,7 +39,7 @@ THE SOFTWARE.
so override @checked manually.
-->
<f:optionalBlock field="${field}" title="${title}" checked="${instance[field]!=null}">
<j:set var="descriptor" value="${app.getDescriptorOrDie(descriptor.getPropertyType(instance,field).clazz)}" />
<j:set var="descriptor" value="${app.getDescriptorOrDie(descriptor.getPropertyTypeOrDie(instance,field).clazz)}" />
<j:set var="instance" value="${instance[field]}"/>
<st:include from="${descriptor}" page="${descriptor.configPage}" />
</f:optionalBlock>
......
......@@ -35,7 +35,7 @@ THE SOFTWARE.
</st:attribute>
</st:documentation>
<f:rowSet name="${field}">
<j:set var="descriptor" value="${attrs.propertyDescriptor ?: app.getDescriptorOrDie(descriptor.getPropertyType(instance,field).clazz)}" />
<j:set var="descriptor" value="${attrs.propertyDescriptor ?: app.getDescriptorOrDie(descriptor.getPropertyTypeOrDie(instance,field).clazz)}" />
<j:set var="instance" value="${instance[field]}"/>
<st:include from="${descriptor}" page="${descriptor.configPage}" />
</f:rowSet>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册