mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
Produce a helpful error message if optionalProperty#field is bogus.
Otherwise get a useless “null is missing its descriptor” from Jenkins.getDescriptorOrDie.
This commit is contained in:
1 parent
871abe5f88
commit
cac3efd90a
3 files changed
+22
-5
No files matched your search
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user