Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333665 - [DOM] Wrong binding generated for Array.clone() method
Summary: [DOM] Wrong binding generated for Array.clone() method
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-06 11:05 EST by arlindolima CLA
Modified: 2020-05-20 11:59 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description arlindolima CLA 2011-01-06 11:05:04 EST
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();"
Comment 1 Olivier Thomann CLA 2011-01-06 11:30:25 EST
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.
Comment 2 Olivier Thomann CLA 2011-01-06 13:31:41 EST
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.
Comment 3 arlindolima CLA 2011-01-06 15:46:02 EST
Related: An array ITypeBinding's DECLARED_FIELDS and DECLARED_METHODS shouldn't be empty. It should have one filed (length) and one method (clone).
Comment 4 Olivier Thomann CLA 2011-01-07 09:19:42 EST
(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 ?
Comment 5 Srikanth Sankaran CLA 2011-01-10 02:17:16 EST
(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.
Comment 6 Olivier Thomann CLA 2011-08-25 09:10:50 EDT
(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 ?
Comment 7 Markus Keller CLA 2014-07-24 09:37:27 EDT
(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)".
Comment 8 Markus Keller CLA 2014-07-24 09:41:36 EDT
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.
Comment 9 Jay Arthanareeswaran CLA 2015-05-12 02:57:13 EDT
Sorry, this needs to be moved out of 4.5.
Comment 10 Jay Arthanareeswaran CLA 2016-04-05 04:34:05 EDT
No progress yet and unlikely to get time during 4.6. Moving out.
Comment 11 Manoj N Palat CLA 2018-05-21 06:07:06 EDT
Bulk move out of 4.8
Comment 12 Eclipse Genie CLA 2020-05-20 11:59:21 EDT
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.