Bug 30076 - [ecj] Annotations don't work with interpreted code
Summary: [ecj] Annotations don't work with interpreted code
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 4.2.0
: P3 major
Target Milestone: 4.3.0
Assignee: Tom Tromey
Depends on:
Blocks: 28067
  Show dependency treegraph
Reported: 2006-12-05 18:47 UTC by Andrew Haley
Modified: 2006-12-08 01:26 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2006-12-08 00:15:19

. (4.59 KB, text/plain)
2006-12-05 18:54 UTC, Andrew Haley
. (4.59 KB, application/x-tar)
2006-12-05 20:12 UTC, Andrew Haley

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Haley 2006-12-05 18:47:37 UTC
Annotations don't work with interpreted code
Comment 1 Andrew Haley 2006-12-05 18:54:51 UTC
Created attachment 12749 [details]

Expected output:

class pp: @A1(enumF=ACE, doubleF=99.0, stringF=A1, arrayF=[1, 2], intF=0, classF=class java.lang.Class, nestedF=@Inner(stringInnerF=class annotation))
class pp: @Another(classF=class java.lang.Integer)
public static void pp.barf(int,int):
    arg 0: @Inner(stringInnerF=Param anno)
    arg 1: @Another(classF=class pp)
    arg 1: @Inner(stringInnerF=second anno)
public static void pp.main(java.lang.String[]):
   @A1(enumF=DEUCE, doubleF=99.0, stringF=ff, arrayF=[33], intF=2868724, classF=class java.lang.Class, nestedF=@Inner(stringInnerF=another method))
public static transient void pp.write(java.lang.String[]):
   @A1(enumF=ACE, doubleF=3.0, stringF=Abandon hope, arrayF=[0], intF=12, classF=class pp, nestedF=@Inner(stringInnerF=method annotation))
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException:
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException:
public boolean java.lang.Object.equals(java.lang.Object):
public int pp.arse:
   @Another(classF=class java.lang.String)
public int pp.too:

What we get:

 ~/gcc/gcj-eclipse-merge-branch/install/bin/gij pp
Exception in thread "main" java.lang.NullPointerException
   at java.lang.Class.getDeclaredAnnotationsInternal(natClass.cc:1389)
   at java.lang.Class.getDeclaredAnnotations(Class.java:1305)
   at java.lang.Class.getAnnotations(Class.java:1275)
   at pp.main(pp.java:80)
Comment 2 Andrew Haley 2006-12-05 19:08:24 UTC
The cause of this bug is that libgcj sorts fields so that static fields come first, followed by instance fields.  Any annotation indexes that refer to a field will be wrong after this.

Comment 3 Andrew Haley 2006-12-05 20:12:13 UTC
Created attachment 12750 [details]
Comment 4 Tom Tromey 2006-12-08 00:15:19 UTC
Also we appear to incorrect create the annotation data
structure for one of the methods.
Comment 5 Tom Tromey 2006-12-08 01:13:51 UTC
I needed this to see correct output.
There's still some oddity where main sorts before barf in the output,
I haven't looked at that.

--- pp.java.~1~	2006-12-05 11:49:25.000000000 -0700
+++ pp.java	2006-12-07 17:53:09.000000000 -0700
@@ -103,7 +103,7 @@
 	int j = 0;
 	Annotation[][] annosAnnos = m.getParameterAnnotations();
-	Arrays.sort(annosAnnos, myCollator);
+	// Arrays.sort(annosAnnos, myCollator);
 	for (Annotation[] a : annosAnnos)
 	    Arrays.sort(a, myCollator);
Comment 6 Tom Tromey 2006-12-08 01:15:56 UTC
Oh, I see.  It is just that we need:

    Arrays.sort(methods, myCollator);
Comment 7 Tom Tromey 2006-12-08 01:19:29 UTC
Subject: Bug 30076

Author: tromey
Date: Fri Dec  8 01:19:17 2006
New Revision: 119644

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119644
	PR libgcj/30076:
	* defineclass.cc (read_fields): Sort fields here.
	(handleFieldsEnd): Removed.
	(handleField): Added field map argument.
	(struct _Jv_ClassReader): Updated.
	(handleParameterAnnotations): Use writeInt for the length.


Comment 8 Tom Tromey 2006-12-08 01:26:31 UTC
Fix checked in.