src/share/classes/java/lang/reflect/Constructor.java

Print this page
rev 10097 : 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
Reviewed-by: duke

*** 542,558 **** * {@inheritDoc} * @since 1.8 */ @Override public AnnotatedType getAnnotatedReceiverType() { ! if (getDeclaringClass().getEnclosingClass() == null) ! return super.getAnnotatedReceiverType(); return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), sun.misc.SharedSecrets.getJavaLangAccess(). ! getConstantPool(getDeclaringClass()), this, ! getDeclaringClass(), ! getDeclaringClass().getEnclosingClass(), TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER); } } --- 542,576 ---- * {@inheritDoc} * @since 1.8 */ @Override public AnnotatedType getAnnotatedReceiverType() { ! Class<?> thisDeclClass = getDeclaringClass(); ! Class<?> enclosingClass = thisDeclClass.getEnclosingClass(); + if (enclosingClass == null) { + // A Constructor for a top-level class + return null; + } + + Class<?> outerDeclaringClass = thisDeclClass.getDeclaringClass(); + if (outerDeclaringClass == null) { + // A constructor for a local or anonymous class + return null; + } + + // Either static nested or inner class + if (Modifier.isStatic(thisDeclClass.getModifiers())) { + // static nested + return null; + } + + // A Constructor for an inner class return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), sun.misc.SharedSecrets.getJavaLangAccess(). ! getConstantPool(thisDeclClass), this, ! thisDeclClass, ! enclosingClass, TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER); } }