From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 60914 invoked by alias); 13 Aug 2015 19:30:55 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 60903 invoked by uid 89); 13 Aug 2015 19:30:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_20,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mail.theptrgroup.com Received: from mail.theptrgroup.com (HELO mail.theptrgroup.com) (71.178.251.9) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Aug 2015 19:30:53 +0000 Received: from [10.11.21.54] (unknown [10.11.21.54]) by mail.theptrgroup.com (Postfix) with ESMTPS id 3B558405CB for ; Thu, 13 Aug 2015 15:30:06 -0400 (EDT) From: Jamison Hope Content-Type: multipart/mixed; boundary="Apple-Mail=_A07DF3C7-AE0F-4A33-A34C-3BC7559530B7" Subject: [PATCH] three annotations-related fixes/enhancements Message-Id: <26455D3A-3751-4667-A0AD-4E99AD145A88@theptrgroup.com> Date: Thu, 13 Aug 2015 19:30:00 -0000 To: Kawa mailing list Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) X-IsSubscribed: yes X-SW-Source: 2015-q3/txt/msg00023.txt.bz2 --Apple-Mail=_A07DF3C7-AE0F-4A33-A34C-3BC7559530B7 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Content-length: 1350 The attached patch fixes 2 bugs and provides 1 new feature: 1. When an annotation entry is read in via the readAnnotationEntry() method of RuntimeAnnotationsAttr, it sets the entry's annotationTypeIndex field, but not its annotationType field. So then later when the annotation is searched for later, we get a NullPointerException in RuntimeAnnotationsAttr.getAnnotation() at this line: if (ann.getAnnotationType().getReflectClass() == clas) { because getAnnotationType() returns null. The first fix is to initialize the annotationType field when the entry is read in. 2. When an annotation value is read in via the readAnnotationValue() method of RuntimeAnnotationsAttr, if the value type is an enum constant, it is stored as a String[] holding the names of the enum class and field. Later on, getAnnotation() returns a Proxy object that will call AnnotationEntry.Value.getValue(). This is supposed to return the appropriate enum constant, but instead returns the String[], leading to a ClassCastException (I think it was). The second fix is to fix Value.getValue() so that if it's of type 'e' (enum), then convert the String[] into the actual enum constant. 3. The third change is an enhancement to give ClassType a getAnnotation() method analogous to the ones in Field and Method. -- Jamison Hope The PTR Group www.theptrgroup.com --Apple-Mail=_A07DF3C7-AE0F-4A33-A34C-3BC7559530B7 Content-Disposition: attachment; filename=gnu-bytecode-annotations.patch Content-Type: application/octet-stream; name="gnu-bytecode-annotations.patch" Content-Transfer-Encoding: 7bit Content-length: 3441 Index: gnu/bytecode/ChangeLog =================================================================== --- gnu/bytecode/ChangeLog (revision 8585) +++ gnu/bytecode/ChangeLog (working copy) @@ -1,3 +1,11 @@ +2015-08-13 Jamison Hope + + * ClassType.java (getAnnotation): New method. + * RuntimeAnnotationsAttr.java (readAnnotationEntry): Set + annotationType when entry is read to avoid NullPointerException in + getAnnotation() later. + * AnnotationEntry.java (Value.getValue): Convert enum values. + 2015-06-04 Per Bothner * PrimType.java (compare): Handle signed vs unsigned types. Index: gnu/bytecode/ClassType.java =================================================================== --- gnu/bytecode/ClassType.java (revision 8585) +++ gnu/bytecode/ClassType.java (working copy) @@ -1128,6 +1128,18 @@ return result; } + public + T getAnnotation(Class clas) { + T ann = RuntimeAnnotationsAttr.getAnnotation(this, clas); + if (ann != null) + return ann; + if ((flags & EXISTING_CLASS) != 0 && getReflectClass() != null) { + Class c = getReflectClass(); + return c.getAnnotation(clas); + } + return null; + } + /** Do various fixups after generating code but before we can write it out. * This includes assigning constant pool indexes where needed, * finalizing labels, etc. */ Index: gnu/bytecode/RuntimeAnnotationsAttr.java =================================================================== --- gnu/bytecode/RuntimeAnnotationsAttr.java (revision 8585) +++ gnu/bytecode/RuntimeAnnotationsAttr.java (working copy) @@ -129,6 +129,7 @@ int tindex = dstr.readUnsignedShort(); CpoolEntry cpentry = constants.getForced(tindex, ConstantPool.UTF8); aentry.annotationTypeIndex = tindex; + aentry.annotationType = (ClassType) Type.signatureToType(((CpoolUtf8)cpentry).getString()); int count = dstr.readUnsignedShort(); for (int i = 0; i < count; i++) { int nindex = dstr.readUnsignedShort(); Index: gnu/bytecode/AnnotationEntry.java =================================================================== --- gnu/bytecode/AnnotationEntry.java (revision 8585) +++ gnu/bytecode/AnnotationEntry.java (working copy) @@ -310,6 +310,31 @@ } return valuex; } + else if (kind == 'e') { + if (valuex == null) { + if (value instanceof Enum) { + valuex = value; + } else { + ClassType type; + String name; + + if (value instanceof Field) { + Field f = (Field) value; + type = f.getDeclaringClass(); + name = f.getName(); + } else { + String[] sarr = (String[]) value; + type = (ClassType) Type.signatureToType(sarr[0]); + name = sarr[1]; + } + Class clas = type.getReflectClass(); + Class eclas = clas.asSubclass(Enum.class); + Enum val = Enum.valueOf(eclas, name); + valuex = val; + } + } + return valuex; + } // FIXME other conversions needed? return value; } --Apple-Mail=_A07DF3C7-AE0F-4A33-A34C-3BC7559530B7--