From 8e0cbbc98b5a0e373a83d7de066f2afe72d553f7 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 28 Apr 2015 19:21:34 -0400 Subject: [PATCH] @kohsuke requested some more comments in the code itself. Given the minefield that is databinding, that seems prudent. --- core/src/main/java/hudson/model/Descriptor.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 5d84d56465..4c5693b933 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -918,13 +918,21 @@ public abstract class Descriptor> implements Saveable { // Descriptors, so we prefer 'kind' if it's present. String kind = jo.optString("kind", null); if (kind != null) { + // Only applies when Descriptor.getId is overridden. + // Note that kind is only supported here, + // *not* inside the StaplerRequest.bindJSON which is normally called by newInstance + // (since Descriptor.newInstance is not itself available to Stapler). + // If you merely override getId for some reason, but use @DataBoundConstructor on your Describable, + // there is no problem; but you can only rely on newInstance being called at top level. d = findById(descriptors, kind); } if (d == null) { kind = jo.optString("$class"); - if (kind != null) { + if (kind != null) { // else we will fall through to the warning + // This is the normal case. d = findByDescribableClassName(descriptors, kind); if (d == null) { + // Deprecated system where stapler-class was the Descriptor class name (rather than Describable class name). d = findByClassName(descriptors, kind); } } @@ -932,7 +940,7 @@ public abstract class Descriptor> implements Saveable { if (d != null) { items.add(d.newInstance(req, jo)); } else { - LOGGER.log(Level.WARNING, "Received unexpected formData: {0}", jo); + LOGGER.log(Level.WARNING, "Received unexpected form data element: {0}", jo); } } } -- GitLab