1.1 --- a/src/share/classes/com/sun/tools/javac/code/AnnoConstruct.java Mon Oct 21 20:10:43 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/AnnoConstruct.java Tue Oct 22 10:08:49 2013 +0200 1.3 @@ -117,17 +117,13 @@ 1.4 annoType.isAnnotationPresent(Inherited.class)) 1.5 return getInheritedAnnotations(annoType); 1.6 1.7 - // Pack them in an array 1.8 - Attribute[] contained0 = null; 1.9 - if (container != null) 1.10 - contained0 = unpackAttributes(container); 1.11 - ListBuffer<Attribute.Compound> compounds = new ListBuffer<>(); 1.12 - if (contained0 != null) { 1.13 - for (Attribute a : contained0) 1.14 - if (a instanceof Attribute.Compound) 1.15 - compounds = compounds.append((Attribute.Compound)a); 1.16 - } 1.17 - Attribute.Compound[] contained = compounds.toArray(new Attribute.Compound[compounds.size()]); 1.18 + Attribute.Compound[] contained = unpackContained(container); 1.19 + 1.20 + // In case of an empty legacy container we might need to look for 1.21 + // inherited annos as well 1.22 + if (direct == null && contained.length == 0 && 1.23 + annoType.isAnnotationPresent(Inherited.class)) 1.24 + return getInheritedAnnotations(annoType); 1.25 1.26 int size = (direct == null ? 0 : 1) + contained.length; 1.27 @SuppressWarnings("unchecked") // annoType is the Class for A 1.28 @@ -159,6 +155,19 @@ 1.29 return arr; 1.30 } 1.31 1.32 + private Attribute.Compound[] unpackContained(Attribute.Compound container) { 1.33 + // Pack them in an array 1.34 + Attribute[] contained0 = null; 1.35 + if (container != null) 1.36 + contained0 = unpackAttributes(container); 1.37 + ListBuffer<Attribute.Compound> compounds = new ListBuffer<>(); 1.38 + if (contained0 != null) { 1.39 + for (Attribute a : contained0) 1.40 + if (a instanceof Attribute.Compound) 1.41 + compounds = compounds.append((Attribute.Compound)a); 1.42 + } 1.43 + return compounds.toArray(new Attribute.Compound[compounds.size()]); 1.44 + } 1.45 1.46 // This method is part of the javax.lang.model API, do not use this in javac code. 1.47 public <A extends Annotation> A getAnnotation(Class<A> annoType) {