From a30ee8291d2257ddf419af680c7adcee5b2cb58d Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 3 Aug 2010 14:28:09 +0000 Subject: [PATCH] Look out for a typical error a plugin developer makes. See http://hudson.361315.n4.nabble.com/Help-Hint-needed-Post-build-action-doesn-t-stay-activated-td2308833.html git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@33544 71c3de6d-444a-0410-be80-ed276b4c234a --- .../src/main/java/hudson/model/Descriptor.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 6afed9cfce..02280fa93b 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -455,15 +455,15 @@ public abstract class Descriptor> implements Saveable { if(!Modifier.isAbstract(m.getDeclaringClass().getModifiers())) { // this class overrides newInstance(StaplerRequest). // maintain the backward compatible behavior - return newInstance(req); + return verifyNewInstance(newInstance(req)); } else { if (req==null) { // yes, req is supposed to be always non-null, but see the note above - return clazz.newInstance(); + return verifyNewInstance(clazz.newInstance()); } // new behavior as of 1.206 - return req.bindJSON(clazz,formData); + return verifyNewInstance(req.bindJSON(clazz,formData)); } } catch (NoSuchMethodException e) { throw new AssertionError(e); // impossible @@ -474,6 +474,18 @@ public abstract class Descriptor> implements Saveable { } } + /** + * Look out for a typical error a plugin developer makes. + * See http://hudson.361315.n4.nabble.com/Help-Hint-needed-Post-build-action-doesn-t-stay-activated-td2308833.html + */ + private T verifyNewInstance(T t) { + if (t!=null && t.getDescriptor()!=this) { + // TODO: should this be a fatal error? + LOGGER.warning("Father of "+ t+" and its getDescriptor() points to two different instances. Probably malplaced @Extension. See http://hudson.361315.n4.nabble.com/Help-Hint-needed-Post-build-action-doesn-t-stay-activated-td2308833.html"); + } + return t; + } + /** * Returns the resource path to the help screen HTML, if any. *