diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index b4add73200..955eaf7f2d 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -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> 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} */ diff --git a/core/src/main/resources/lib/form/optionalProperty.jelly b/core/src/main/resources/lib/form/optionalProperty.jelly index 7b2827448a..cccf94e70c 100644 --- a/core/src/main/resources/lib/form/optionalProperty.jelly +++ b/core/src/main/resources/lib/form/optionalProperty.jelly @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> - + Renders inline an optional single-value nested data-bound property of the current instance, @@ -39,7 +39,7 @@ THE SOFTWARE. so override @checked manually. --> - + diff --git a/core/src/main/resources/lib/form/property.jelly b/core/src/main/resources/lib/form/property.jelly index 522452cc6e..a0cb378225 100644 --- a/core/src/main/resources/lib/form/property.jelly +++ b/core/src/main/resources/lib/form/property.jelly @@ -35,7 +35,7 @@ THE SOFTWARE. - +