Fix [JACKSON-757]
diff --git a/release-notes/CREDITS b/release-notes/CREDITS index 4d0f93d..1120544 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS
@@ -846,5 +846,6 @@ getEmbeddedObject() [1.9.4] - - \ No newline at end of file +Stephan Bailliez: + * Reported [JACKSON-757] Problems with Enum values, annotations on constructors + [1.9.4]
diff --git a/release-notes/VERSION b/release-notes/VERSION index 056e515..bad3a3d 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION
@@ -16,6 +16,8 @@ * [JACKSON-753] JsonParserDelegate missing delegation of getBooleanValue(), getEmbeddedObject() (reported by Sebastian T) + * [JACKSON-757] Problems with Enum values, annotations on constructors + (reported by Stephan B) (all fixes up to 1.8.8)
diff --git a/src/mapper/java/org/codehaus/jackson/map/introspect/AnnotatedClass.java b/src/mapper/java/org/codehaus/jackson/map/introspect/AnnotatedClass.java index a2e9d40..42afb88 100644 --- a/src/mapper/java/org/codehaus/jackson/map/introspect/AnnotatedClass.java +++ b/src/mapper/java/org/codehaus/jackson/map/introspect/AnnotatedClass.java
@@ -775,17 +775,32 @@ * (for non-static inner classes) are NOT included, but type is? Strange, sounds like * a bug. Alas, we can't really fix that... */ - AnnotationMap[] resolvedAnnotations; + /* Also: [JACKSON-767] (enum value constructors) + */ + AnnotationMap[] resolvedAnnotations = null; if (paramCount != paramAnns.length) { - // only cover one "missing" annotation, and only for member classes; to try to avoid - // false "fixes" for possible other error cases - if (ctor.getDeclaringClass().isMemberClass() && paramCount == (paramAnns.length + 1)) { - // hack attack: prepend a null entry to make things match - Annotation[][] old = paramAnns; - paramAnns = new Annotation[old.length+1][]; - System.arraycopy(old, 0, paramAnns, 1, old.length); - resolvedAnnotations = _collectRelevantAnnotations(paramAnns); - } else { + // Limits of the work-around (to avoid hiding real errors): + // first, only applicable for member classes and then either: + + Class<?> dc = ctor.getDeclaringClass(); + if (dc.isMemberClass()) { + // (a) just one annotation (for non-static inner classes) + if (paramCount == (paramAnns.length + 1)) { + // hack attack: prepend a null entry to make things match + Annotation[][] old = paramAnns; + paramAnns = new Annotation[old.length+1][]; + System.arraycopy(old, 0, paramAnns, 1, old.length); + resolvedAnnotations = _collectRelevantAnnotations(paramAnns); + + // (b) or is enum, which have two extra hidden params (but not for annotations!) + } else if (dc.isEnum() && (paramCount == paramAnns.length + 2)) { + Annotation[][] old = paramAnns; + paramAnns = new Annotation[old.length+2][]; + System.arraycopy(old, 0, paramAnns, 2, old.length); + resolvedAnnotations = _collectRelevantAnnotations(paramAnns); + } + } + if (resolvedAnnotations == null) { throw new IllegalStateException("Internal error: constructor for "+ctor.getDeclaringClass().getName() +" has mismatch: "+paramCount+" parameters; "+paramAnns.length+" sets of annotations"); }