Community
Participate
Working Groups
Build Identifier: M20100909-0800 The clone() method in an array generates a binding to the Object.clone() method. However, it is stated in JLS3 ยง10.7: "The members of an array type are all of the following: . . . The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions. . . . All the members inherited from class Object; the only method of Object that is not inherited is its clone method." This means, the binding should be targeted to the Array implementation of clone(). Reproducible: Always Steps to Reproduce: 1. Check the binding of the following statement: "Integer[] a = ( new Integer[2]).clone();"
The declaring class should indeed be Integer[] as shown in the disassembled code: // Method descriptor #15 ([Ljava/lang/String;)V // Stack: 2, Locals: 2 public static void main(String[] args); 0 iconst_2 1 anewarray Integer [16] 4 invokevirtual Integer[].clone() : Object [18] 7 checkcast Integer[] [19] 10 astore_1 [a] 11 getstatic System.out : PrintStream [24] 14 aload_1 [a] 15 invokevirtual PrintStream.println(Object) : void [30] 18 return Investigating what binding we get in this case.
Note that this is true only if the source option is 1.5 or above. In 1.4 or below, the code doesn't compile.
Related: An array ITypeBinding's DECLARED_FIELDS and DECLARED_METHODS shouldn't be empty. It should have one filed (length) and one method (clone).
(In reply to comment #3) > Related: An array ITypeBinding's DECLARED_FIELDS and DECLARED_METHODS shouldn't > be empty. It should have one filed (length) and one method (clone). I have some problem with this as an array ITypeBinding has no declaring type declaration as is. So I don't see how we can have declared fields or methods. Srikanth, any thoughts on this ?
(In reply to comment #4) > (In reply to comment #3) > > Related: An array ITypeBinding's DECLARED_FIELDS and DECLARED_METHODS shouldn't > > be empty. It should have one filed (length) and one method (clone). > I have some problem with this as an array ITypeBinding has no declaring type > declaration as is. So I don't see how we can have declared fields or methods. > > Srikanth, any thoughts on this ? This looks similar to bug 330328. Right now the javadoc on ITypeBinding says: "an array type - array types are referenced but not explicitly declared". Perhaps this could be expanded upon a bit.
(In reply to comment #5) > This looks similar to bug 330328. Right now the javadoc on ITypeBinding > says: "an array type - array types are referenced but not explicitly > declared". Perhaps this could be expanded upon a bit. What do you suggest ?
(In reply to Olivier Thomann from comment #6) > What do you suggest ? See comment 3. (In reply to Olivier Thomann from comment #4) > I have some problem with this as an array ITypeBinding has no declaring type > declaration as is. So I don't see how we can have declared fields or methods. We already have a type binding for the array type, so it totally makes sense to give it the field and method that are declared in JLS8 10.7. For a type/member to exist in the model, it doesn't have to be declared in a class file. In this snippet, the IMethodBinding for "add" also has a non-null getDeclaringClass(), whose getDeclaredMethods() includes this method again: List<String> al= new ArrayList<>(); al.add("Hi"); And all that although there's no declaration for type List<String> nor for its method with signature "boolean add(String)".
This should only be implemented in a new AST#apiLevel(), since existing clients may rely on the "getDeclaringClass() == null" check to find out whether a "length" field is from an array type.
Sorry, this needs to be moved out of 4.5.
No progress yet and unlikely to get time during 4.6. Moving out.
Bulk move out of 4.8
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.