This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libgcj/12416] New: java.lang.Class.getFields returns duplicate entries.
- From: "suckfish at ihug dot co dot nz" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Sep 2003 04:12:14 -0000
- Subject: [Bug libgcj/12416] New: java.lang.Class.getFields returns duplicate entries.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12416
Summary: java.lang.Class.getFields returns duplicate entries.
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: libgcj
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: suckfish at ihug dot co dot nz
CC: gcc-bugs at gcc dot gnu dot org
/*
The reflection APIs work in a manner inconsistent with the sun java
sdk when an interface is inherited multiple times.
The java.lang.Class.getFields() method in libjava returns a field once
for each inheritence path to it. Sun java only returns the field
once.
$ dev/test/bin/gcj -o printfields --main=printfields printfields.java ~]
$ LD_LIBRARY_PATH=./dev/test/lib ./printfields
public static final int A.a
public static final int A.a
$ /usr/java/j2sdk1.4.2/bin/javac printfields.java
$ /usr/java/j2sdk1.4.2/bin/java printfields
public static final int A.a
The sun documentation doesn't explicitly say what should happen in
this case, but my reading is that a field should only occur once.
With the current implementation, it appears possible to
crash the java.lang.Class implementation with a pathological case
... although getting the compiler to compile such a case would be
interesting...
[nitpicking while waiting for a bootstrap to run.]
*/
interface A
{
int a = 0;
}
interface B extends A
{
}
interface C extends A
{
}
public class printfields implements B, C
{
static public void main (String[] unused)
{
java.lang.reflect.Field[] fields = printfields.class.getFields();
for (int i = 0; i != fields.length; ++i) {
System.out.println (fields[i]);
}
}
}