Bug 12416 - java.lang.Class.getFields returns duplicate entries.
Summary: java.lang.Class.getFields returns duplicate entries.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 3.4.0
: P3 minor
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-26 04:12 UTC by Ralph Loader
Modified: 2003-10-22 19:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-09-29 00:44:57


Attachments
Test case that crashes java interpreter (751 bytes, text/plain)
2003-09-28 10:12 UTC, Ralph Loader
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralph Loader 2003-09-26 04:12:11 UTC
/*
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]);
	}
    }
}
Comment 1 Ralph Loader 2003-09-28 10:12:28 UTC
Created attachment 4845 [details]
Test case that crashes java interpreter

Neither sun's javac nor gcj are up to compiling this test case from source.

So instead I wrote a shell script that generates the .class files, and then
runs the interpreter on them.  You need a sed that is OK with binary files -
GNU sed is, it seems.

This results in gij segfaulting.

Takes about 2 minutes CPU on my PIII 933.
Comment 2 GCC Commits 2003-10-22 19:28:20 UTC
Subject: Bug 12416

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tromey@gcc.gnu.org	2003-10-22 19:28:15

Modified files:
	libjava/testsuite: ChangeLog 
Added files:
	libjava/testsuite/libjava.lang: PR12416.java PR12416.out 

Log message:
	PR libgcj/12416:
	* libjava.lang/PR12416.out: New file.
	* libjava.lang/PR12416.java: New file.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.295&r2=1.296
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.lang/PR12416.java.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.lang/PR12416.out.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 3 GCC Commits 2003-10-22 19:29:33 UTC
Subject: Bug 12416

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tromey@gcc.gnu.org	2003-10-22 19:29:28

Modified files:
	libjava        : ChangeLog 
	libjava/java/lang: Class.h Class.java natClass.cc 

Log message:
	PR libgcj/12416:
	* java/lang/Class.h: Updated.
	* java/lang/natClass.cc (_getFields): Removed.
	(getFields): Likewise.
	(getDeclaredFields): Added `public_only' parameter.
	* java/lang/Class.java (getFields): Now implemented in java; from
	Classpath.
	(getDeclaredFields): Likewise.
	(getDeclaredFields(boolean)): Declare.
	(_getFields): Removed.
	(internalGetFields): New method, from Classpath.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.2290&r2=1.2291
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/Class.h.diff?cvsroot=gcc&r1=1.60&r2=1.61
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/Class.java.diff?cvsroot=gcc&r1=1.18&r2=1.19
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/natClass.cc.diff?cvsroot=gcc&r1=1.66&r2=1.67

Comment 4 Tom Tromey 2003-10-22 19:29:44 UTC
I've checked in a fix for this.