From 4857164a45c531e9d83423f0fa37719d490087db Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 4 Aug 2009 00:39:21 +0000 Subject: [PATCH] Added extra type checking to detect problems like http://www.nabble.com/Creating-a-new-parameter-Type-%3A-Masked-Parameter-td24786554.html early on. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@20440 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/Descriptor.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 805e0f66fb..975e97bef2 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -225,6 +225,18 @@ public abstract class Descriptor> implements Saveable { if(!t.isAssignableFrom(clazz)) throw new AssertionError("Outer class "+clazz+" of "+getClass()+" is not assignable to "+t+". Perhaps wrong outer class?"); } + + // detect a type error. this Descriptor is supposed to be returned from getDescriptor(), so make sure its type match up. + // this prevents a bug like http://www.nabble.com/Creating-a-new-parameter-Type-%3A-Masked-Parameter-td24786554.html + try { + Method getd = clazz.getMethod("getDescriptor"); + if(!getd.getReturnType().isAssignableFrom(getClass())) { + throw new AssertionError(getClass()+" must be assignable to "+getd.getReturnType()); + } + } catch (NoSuchMethodException e) { + throw new AssertionError(getClass()+" is missing getDescriptor method."); + } + } /** -- GitLab