Bug 221723 - Override method fails with and error saying "1" due to a java.lang.ArrayIndexOutOfBoundsException:
Summary: Override method fails with and error saying "1" due to a java.lang.ArrayIndex...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.4 M6   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 207496 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-03-06 14:45 EST by Pablo Ilardi CLA
Modified: 2008-03-25 12:04 EDT (History)
3 users (show)

See Also:


Attachments
This is the source code file Im working on (2.50 KB, text/x-java)
2008-03-06 14:45 EST, Pablo Ilardi CLA
no flags Details
Proposed patch (1.96 KB, patch)
2008-03-13 10:49 EDT, David Audel CLA
no flags Details | Diff
Proposed patch + regression test (36.90 KB, patch)
2008-03-14 06:15 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pablo Ilardi CLA 2008-03-06 14:45:29 EST
Created attachment 91791 [details]
This is the source code file Im working on

Build ID: M20071023-1652

Steps To Reproduce:
It is not that easy to reproduce it only happens with a source file I'm working on, it fails with the source->override / implement dialog, and also by editing the code manually with the code expansion Ctrl+SPACE

I'm pasting the class code bellow, hope it helps:

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.widget.SimpleCursorAdapter;

public class Notepadv1 extends ListActivity {

	private NotesDbAdapter mDbHelper;

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		this.setContentView(R.layout.notepad_list);
		this.mDbHelper = new NotesDbAdapter(this);
		this.mDbHelper.open();
		this.fillData();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		boolean result = super.onCreateOptionsMenu(menu);
		menu.add(0, 0, R.string.menu_insert, new Runnable() {
			@Override
			public void run() {
				Notepadv1.this.createNote();
			}
		});

		menu.add(0, 0, R.string.menu_delete, new Runnable() {
			@Override
			public void run() {
				Notepadv1.this.deleteNote();
			}
		});
		return result;
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, String data, Bundle extras) {
		super.onActivityResult(requestCode, resultCode, data, extras);
	}
}
, when I try to override the method:

	@Override
	protected void onListItemClick(android.widget.ListView l, android.view.View v, int position, long id) {
.....
	}

it fails with the given message in the summary.

Thanks.


More information:
The log message says:

!ENTRY org.eclipse.ui 4 0 2008-03-06 17:36:52.300
!MESSAGE 1
!STACK 0
java.lang.ArrayIndexOutOfBoundsException: 1
        at org.eclipse.jdt.internal.codeassist.InternalCompletionProposal.findMethodParameterNames(InternalCompletionProposal.java:122)
        at org.eclipse.jdt.core.CompletionProposal.findParameterNames(CompletionProposal.java:1854)
        at org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider.appendUnboundedParameterList(CompletionProposalLabelProvider.java:96)
        at org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider.createMethodProposalLabel(CompletionProposalLabelProvider.java:255)
        at org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider.createLabel(CompletionProposalLabelProvider.java:512)
        at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.computeDisplayString(LazyJavaCompletionProposal.java:227)
        at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.getDisplayString(LazyJavaCompletionProposal.java:217)
        at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.isValidPrefix(AbstractJavaCompletionProposal.java:710)
        at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.isValidPrefix(LazyJavaCompletionProposal.java:340)
        at org.eclipse.jdt.internal.ui.text.java.JavaMethodCompletionProposal.isValidPrefix(JavaMethodCompletionProposal.java:209)
        at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.validate(AbstractJavaCompletionProposal.java:677)
        at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.apply(AbstractJavaCompletionProposal.java:431)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:806)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$21(CompletionProposalPopup.java:770)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:417)
        at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
Comment 1 Olivier Thomann CLA 2008-03-06 14:50:09 EST
Could you please check if this works with 3.3.2 ?
Comment 2 David Audel CLA 2008-03-10 09:03:19 EDT
I don't reproduce the problems.

The problem is not only in code assist (ctrl+space) because the source->override / implement dialog doesn't call code assist code.

The stacktrace given in comment 0 is created when a completion of a method reference and not a completion of a method declaration. The preference 'Java/Editor/Content Assist/Insert single proposals automatically' is probably enabled and the preference 'Java/Editor/Content Assist/Fill argument names on completion' is probably disabled.

Could you confirm my supposition ?

example 1 - completion of a method reference:
class Notepadv1 extends ListActivity {
  void foo() {
    onListItemClick| // do ctrl+space at |
  }
}

example 2 - completion of a method declaration:
class Notepadv1 extends ListActivity {
  void foo() {
  }
  onListItemClick| // do ctrl+space at |
}


In your project 'ListActivity' is probably inside a classfile.
Does this classfile has source attachment ?
Does this classfile has javadoc attachment ?

The exception could occur if the method 'onListItemClick' has four arguments in the classfile and if this method has less arguments in the source attachment or the javadoc attachment.

Is it true in your workspace ?

Comment 3 Pablo Ilardi CLA 2008-03-10 09:41:26 EDT
Sorry Oliver sorry but I don't have eclipse 3.3.2 installed.

I think that the issue is something related to what David says. The class file is part of a library provided by a plugin, actually it is provided by the Android SDK. 
This library doesn't provide source attachment but it provides the Javadoc binding. The method I'm trying to override takes 4 arguments, accessing the Javadoc also fails to show the comments, maybe the method is not present in the Javadoc or it is with a different signature (which makes is a different method).

I also tried inspecting the class hierarchy and I can't also find the method there. Anyway I know that the method is there because the decompiler shows it and if I override it manually with the @Override annotation if compiles fine.

Thanks.

(In reply to comment #2)
> I don't reproduce the problems.
> 
> The problem is not only in code assist (ctrl+space) because the
> source->override / implement dialog doesn't call code assist code.
> 
> The stacktrace given in comment 0 is created when a completion of a method
> reference and not a completion of a method declaration. The preference
> 'Java/Editor/Content Assist/Insert single proposals automatically' is probably
> enabled and the preference 'Java/Editor/Content Assist/Fill argument names on
> completion' is probably disabled.
> 
> Could you confirm my supposition ?
> 
> example 1 - completion of a method reference:
> class Notepadv1 extends ListActivity {
>   void foo() {
>     onListItemClick| // do ctrl+space at |
>   }
> }
> 
> example 2 - completion of a method declaration:
> class Notepadv1 extends ListActivity {
>   void foo() {
>   }
>   onListItemClick| // do ctrl+space at |
> }
> 
> 
> In your project 'ListActivity' is probably inside a classfile.
> Does this classfile has source attachment ?
> Does this classfile has javadoc attachment ?
> 
> The exception could occur if the method 'onListItemClick' has four arguments in
> the classfile and if this method has less arguments in the source attachment or
> the javadoc attachment.
> 
> Is it true in your workspace ?
> 

Comment 4 David Audel CLA 2008-03-13 06:11:19 EDT
Pablo - Does the attached javadoc for ListActivity looks like standard javadoc ?
If no, does it looks like http://code.google.com/android/reference/android/app/ListActivity.html ?
Comment 5 Pablo Ilardi CLA 2008-03-13 07:29:44 EDT
(In reply to comment #4)

David, the attached javadoc is like the link you provided, besides how it looks (I think that it is just a css change) it has some little structural differences with the standard one, some of them are related to how it shows the class summary.
Comment 6 David Audel CLA 2008-03-13 07:52:32 EDT
I found the problem.

BinaryMethod#extractJavadoc() is unable to extract the javadoc of the method because 'onListItemClick' is the last method in the html file and there is no other <A> tag after that location. When extractJavadoc() fails, BinaryMethod#getParameterNames() returns invalid results and can cause the ArrayIndexOutOfBoundsException.

BinaryMethod#extractJavadoc() should be improved to support this case.
BinaryMethod#getParameterNames() should return default parameter names when extractJavadoc() fails.
Comment 7 David Audel CLA 2008-03-13 10:49:06 EDT
Created attachment 92443 [details]
Proposed patch
Comment 8 David Audel CLA 2008-03-14 06:15:06 EDT
Created attachment 92552 [details]
Proposed patch + regression test
Comment 9 David Audel CLA 2008-03-14 06:17:10 EDT
Released for 3.4M6.

Test added
  AttachedJavadocTests#test023()
Comment 10 David Audel CLA 2008-03-14 06:20:43 EDT
*** Bug 207496 has been marked as a duplicate of this bug. ***
Comment 11 Jerome Lanneluc CLA 2008-03-25 12:04:55 EDT
Verified for 3.4M6 using I20080325-0100