From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6789 invoked by alias); 25 Feb 2005 19:49:03 -0000 Mailing-List: contact java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org Received: (qmail 6736 invoked by uid 48); 25 Feb 2005 19:48:59 -0000 Date: Sat, 26 Feb 2005 16:13:00 -0000 From: "bonniot at users dot sf dot net" To: java-prs@gcc.gnu.org Message-ID: <20050225194856.20215.bonniot@users.sf.net> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug java/20215] New: gcj does not accept classes with same name fields X-Bugzilla-Reason: CC X-SW-Source: 2005-q1/txt/msg00531.txt.bz2 List-Id: According to the JVM spec, class files can have several fields with the same name. As long as they have different types, they will be distinguished since all field operations specify both the name and the field of the field. Sun's JVM accepts such classes, and correctly distinguishes the fields, as you can see in the attached testcase. Here is the disassembly of this class: Access flags: 0x20 super This class: 2=DuplicateField, super: 4=java.lang.Object Interfaces (count: 0): Fields (count: 2): Field name:"foo" static Signature: 6=java.lang.String Field name:"foo" static Signature: 7=int Methods (count: 3): Method name:"" Signature: 9=()void Attribute "Code", length:17, max_stack:1, max_locals:1, code_length:5 0: aload_0 1: invokespecial #11= ()void> 4: return Method name:"main" public static Signature: 14=(java.lang.String[])void Attribute "Code", length:31, max_stack:2, max_locals:1, code_length:19 0: getstatic #20= 3: getstatic #22= 6: invokevirtual #28= 9: getstatic #20= 12: getstatic #30= 15: invokevirtual #33= 18: return Method name:"" static Signature: 9=()void Attribute "Code", length:24, max_stack:1, max_locals:0, code_length:12 0: ldc #36= 2: putstatic #22= 5: sipush 42 8: putstatic #30= 11: return Sun's JVM correctly executes that program: $ java DuplicateField WOW 42 gcj fails during compilation with: $ gcj DuplicateField.class DuplicateField.java: In class 'DuplicateField': DuplicateField.java: In method 'DuplicateField.main(java.lang.String[])': DuplicateField.java:0: error: mismatching signature for field 'foo' in 'DuplicateField' DuplicateField.java: In method 'DuplicateField.()': DuplicateField.java:0: error: mismatching signature for field 'foo' in 'DuplicateField' Surprisingly, gij also fails with: Exception in thread "main" java.lang.NullPointerException at java.io.PrintStream.println(java.lang.String) (/tmp/gcc/lib/libgcj.so.6.0.0) at DuplicateField.main(java.lang.String[]) (Unknown Source) at gnu.java.lang.MainThread.call_main() (/tmp/gcc/lib/libgcj.so.6.0.0) at gnu.java.lang.MainThread.run() (/tmp/gcc/lib/libgcj.so.6.0.0) gcj (GCC) 4.0.0 20050223 -- Summary: gcj does not accept classes with same name fields Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: java AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bonniot at users dot sf dot net CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20215