Skip to content
Permalink
Browse files
[FIXED JENKINS-37997] FIX NPE when descriptor is not in DescriptorList (
#2536)

For example when Descriptor was defined as field and without @extension .

Signed-off-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com>
  • Loading branch information
KostyaSha authored and oleg-nenashev committed Sep 9, 2016
1 parent d4169af commit 5d3b23daf7e52c511fd594665ef8d648bb7bb121
Showing with 8 additions and 1 deletion.
  1. +7 −1 core/src/main/java/hudson/model/Descriptor.java
  2. +1 −0 core/src/main/java/jenkins/model/Jenkins.java
@@ -638,7 +638,13 @@ public Object instantiate(Class actualType, JSONObject json) {
if (isApplicable(actualType, json)) {
LOGGER.log(Level.FINE, "switching to newInstance {0} {1}", new Object[] {actualType.getName(), json});
try {
return Jenkins.getActiveInstance().getDescriptor(actualType).newInstance(Stapler.getCurrentRequest(), json);
final Descriptor descriptor = Jenkins.getActiveInstance().getDescriptor(actualType);
if (descriptor != null) {
return descriptor.newInstance(Stapler.getCurrentRequest(), json);
} else {
LOGGER.log(Level.WARNING, "Descriptor not found. Falling back to default instantiation "
+ actualType.getName() + " " + json);
}
} catch (Exception x) {
LOGGER.log(Level.WARNING, "falling back to default instantiation " + actualType.getName() + " " + json, x);
// If nested objects are not using newInstance, bindJSON will wind up throwing the same exception anyway,
@@ -1414,6 +1414,7 @@ public Descriptor getDescriptorByName(String id) {
* If you have an instance of {@code type} and call {@link Describable#getDescriptor()},
* you'll get the same instance that this method returns.
*/
@CheckForNull
public Descriptor getDescriptor(Class<? extends Describable> type) {
for( Descriptor d : getExtensionList(Descriptor.class) )
if(d.clazz==type)

0 comments on commit 5d3b23d

Please sign in to comment.