diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index f91114eb62bc3f391d1695b2f35d2425a043b0f7..940b8beab947af9646a0fec21d5a1b04243c2edf 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -910,6 +910,9 @@ public abstract class Descriptor> implements Saveable { for (Object o : JSONArray.fromObject(formData)) { JSONObject jo = (JSONObject)o; Descriptor d = null; + // 'kind' and '$class' are mutually exclusive (see class-entry.jelly), but to be more lenient on the reader side, + // we check them both anyway. 'kind' (which maps to ID) is more unique than '$class', which can have multiple matching + // Descriptors, so we prefer 'kind' if it's present. String kind = jo.optString("kind", null); if (kind != null) { d = findById(descriptors, kind); diff --git a/core/src/main/resources/lib/form/class-entry.jelly b/core/src/main/resources/lib/form/class-entry.jelly index 89a1076798b4b5f538fdbaa5e40bdfb372af76ea..c5e1575e860bb19bc6a39c006af1926a9b5ce4e8 100644 --- a/core/src/main/resources/lib/form/class-entry.jelly +++ b/core/src/main/resources/lib/form/class-entry.jelly @@ -26,6 +26,16 @@ THE SOFTWARE. xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> Invisible <f:entry> type for embedding a descriptor's $class field. + + Most of the time a Descriptor has an unique class name that we can use to instantiate the right Describable + class, so we use the '$class' to represent that to clarify the intent. + + In some other times, such as templates, there are multiple Descriptors with the same Descriptor.clazz + but different IDs, and in that case we put 'kind' to indicate that. In this case, to avoid confusing + readers we do not put non-unique '$class'. + + See Descriptor.newInstancesFromHeteroList for how the reader side is handled. + The describable class that we are instantiating via structured form submission. @@ -41,8 +51,7 @@ THE SOFTWARE. - - +