Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 418092

Summary: ArrayOutOfBoundException while autocompleting a jar library with attached javadoc
Product: [Eclipse Project] JDT Reporter: Alex Falappa <alex.falappa>
Component: CoreAssignee: Jay Arthanareeswaran <jarthana>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: daniel_megert, dirk.ziegenbalg, jarthana, javier.villa00, jritchey, manoj.palat, tparker
Version: 4.3.1Flags: jarthana: review+
manoj.palat: review+
Target Milestone: 4.4 RC1   
Hardware: All   
OS: All   
Whiteboard:

Description Alex Falappa CLA 2013-09-26 08:38:43 EDT
Fresh install of Eclipse 4.3 with a new workspace.
Create a new maven based projects based on the quickstart archetype.
Add a dependency on org.jooq:jooq:3.1 (http://www.jooq.org/)
Create a new class with a main method.
In the method type:
    DSLContext ctx=DSL.using(SQLDialect.ORACLE);
    ctx.  <- autocompletion pops up here
Press 's' (to look for 'select' method)

Autocompletion stops working and the following exception is logged in the error.log:
Message: Unhandled event loop exception
Stack trace: org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.ArrayIndexOutOfBoundsException: 1)
	at org.eclipse.swt.SWT.error(SWT.java:4397)
	at org.eclipse.swt.SWT.error(SWT.java:4312)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3717)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3366)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:610)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
	at org.eclipse.jdt.internal.codeassist.InternalCompletionProposal.findMethodParameterNames(InternalCompletionProposal.java:314)
	at org.eclipse.jdt.internal.codeassist.InternalCompletionProposal.findParameterNames(InternalCompletionProposal.java:1440)
	at org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider.appendUnboundedParameterList(CompletionProposalLabelProvider.java:113)
	at org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider.createMethodProposalLabel(CompletionProposalLabelProvider.java:272)
	at org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider.createStyledLabel(CompletionProposalLabelProvider.java:570)
	at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.computeDisplayString(LazyJavaCompletionProposal.java:263)
	at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.getDisplayString(LazyJavaCompletionProposal.java:246)
	at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.isValidPrefix(AbstractJavaCompletionProposal.java:802)
	at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.isValidPrefix(LazyJavaCompletionProposal.java:378)
	at org.eclipse.jdt.internal.ui.text.java.JavaMethodCompletionProposal.isValidPrefix(JavaMethodCompletionProposal.java:289)
	at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.validate(AbstractJavaCompletionProposal.java:754)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeFilteredProposals(CompletionProposalPopup.java:1486)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$4(CompletionProposalPopup.java:1449)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$1.run(CompletionProposalPopup.java:375)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	... 24 more

Googling for a solution I've also found the same issue reported in the following bug report on a different library:
https://code.google.com/p/projectlombok/issues/detail?id=545

Session data:
eclipse.buildId=4.3.0.I20130605-2000
java.version=1.7.0_25
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=it_IT
Framework arguments:  -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.jee.product
Comment 1 Alex Falappa CLA 2013-09-27 02:40:45 EDT
After additional investigation I've found that the mentioned exception does not occur in a normal java project and if the jooq jar is manually added to the build path. This may mean that the problem may lie in the plugin that manages Maven dependencies (m2e plugin?).

Reassigning to m2e.
Comment 2 Alex Falappa CLA 2013-10-01 12:28:15 EDT
Further investigation after upgrading to Kepler 4.3 SR1 and downgrading jdk to 7u25 to prevent other anomalies.

The problem is not linked to maven projects, as it presents on normal java projects too, but to the presence of the javadoc attachment to the jooq library. If the javadoc attachment is removed completion works flawlessly.

Reassigning to JDT.
Comment 3 Dani Megert CLA 2013-10-02 03:42:38 EDT
(In reply to Alex Falappa from comment #2)
> Further investigation after upgrading to Kepler 4.3 SR1 and downgrading jdk
> to 7u25 to prevent other anomalies.
> 
> The problem is not linked to maven projects, as it presents on normal java
> projects too, but to the presence of the javadoc attachment to the jooq
> library. If the javadoc attachment is removed completion works flawlessly.

I suspect that the attached Javadoc does not match the actual/binary code. Can you check that?
Comment 4 Alex Falappa CLA 2013-10-04 08:57:03 EDT
Sorry for late feedback.

At a first glance the javadoc jar content seems to correspond (you can download it at http://repo1.maven.org/maven2/org/jooq/jooq/3.1.0/jooq-3.1.0-javadoc.jar).

As an additional note by attaching a remote javadoc to the jooq jar (pointing at http://www.jooq.org/javadoc/latest/) all works nicely.
Comment 5 Dani Megert CLA 2014-01-09 04:33:29 EST
See bug 414024 comment 13 for a self-contained test case.
Comment 6 Martin Mathew CLA 2014-02-12 19:47:48 EST
*** Bug 414024 has been marked as a duplicate of this bug. ***
Comment 7 Javier Villa CLA 2014-03-04 11:09:25 EST
I noticed this with a project including the google guava libraries and can confirm the relation with Javadocs:

Bug happens with a user library configured with:

JAR file: guava-16.0.1.jar
Javadorc JAR file: guava-16.0.1-javadoc.jar

Obtained from google at https://code.google.com/p/guava-libraries/

Removing the Javadoc caused the bug to stop happening.
Comment 8 Terry Parker CLA 2014-03-06 19:59:02 EST
The issue here is an overly simplistic searching of Javadoc for the the function's parameter list. If you have a function signature like:

  @GwtIncompatible("NavigableSet")
  @SuppressWarnings("unchecked")
  public static <E> NavigableSet<E> filter(
      NavigableSet<E> unfiltered, Predicate<? super E> predicate) {
    ...
  }

the generated Javadoc is:
<h4>filter</h4>
<pre><a href="../../../../com/google/common/annotations/GwtIncompatible.html" title="annotation in com.google.common.annotations">@GwtIncompatible</a>(<a href="../../../../com/google/common/annotations/GwtIncompatible.html#value()">value</a>="NavigableSet")
public static&nbsp;&lt;E&gt;&nbsp;java.util.NavigableSet&lt;E&gt;&nbsp;filter(java.util.NavigableSet&lt;E&gt;&nbsp;unfiltered,
                                                        <a href="../../../../com/google/common/base/Predicate.html" title="interface in com.google.common.base">Predicate</a>&lt;? super E&gt;&nbsp;predicate)</pre>

The code in BinaryMethod.getParameterNames() near line 352 extracts parameters by searching for the first occurrence of "(", and thus extracts the single parameter to the first annotation, not the two parameters to the function. The array size mismatch is what causes the ArrayOutOfBoundException.

The second issue here is that once the runtime exception has been triggered, keyboard and mouse focus is lost, and the only recourse is to kill Eclipse. I'm not as sure about the best way to protect against that, but it looks like the problem is that org.eclipse.jface.text.contentassist.CompletionProposalPopup never unregisters its fFocusHelper. Perhaps that can be remedied by wrapping the call to handleSetData() in CompletionProposalPopup's SetData listener in a try/catch block, catching RuntimeException and invoking hide() before rethrowing the exception?
Comment 9 Terry Parker CLA 2014-03-07 18:55:19 EST
(In reply to Terry Parker from comment #8)
> The issue here is an overly simplistic searching of Javadoc for the the
> function's parameter list. If you have a function signature like:
> 
>   @GwtIncompatible("NavigableSet")
>   @SuppressWarnings("unchecked")
>   public static <E> NavigableSet<E> filter(
>       NavigableSet<E> unfiltered, Predicate<? super E> predicate) {
>     ...
>   }
> 
> the generated Javadoc is:
> <h4>filter</h4>
> <pre><a
> href="../../../../com/google/common/annotations/GwtIncompatible.html"
> title="annotation in com.google.common.annotations">@GwtIncompatible</a>(<a
> href="../../../../com/google/common/annotations/GwtIncompatible.
> html#value()">value</a>="NavigableSet")
> public
> static&nbsp;&lt;E&gt;&nbsp;java.util.NavigableSet&lt;E&gt;&nbsp;filter(java.
> util.NavigableSet&lt;E&gt;&nbsp;unfiltered,
>                                                         <a
> href="../../../../com/google/common/base/Predicate.html" title="interface in
> com.google.common.base">Predicate</a>&lt;? super E&gt;&nbsp;predicate)</pre>
> 
> The code in BinaryMethod.getParameterNames() near line 352 extracts
> parameters by searching for the first occurrence of "(", and thus extracts
> the single parameter to the first annotation, not the two parameters to the
> function. The array size mismatch is what causes the
> ArrayOutOfBoundException.
> 
> The second issue here is that once the runtime exception has been triggered,
> keyboard and mouse focus is lost, and the only recourse is to kill Eclipse.
> I'm not as sure about the best way to protect against that, but it looks
> like the problem is that
> org.eclipse.jface.text.contentassist.CompletionProposalPopup never
> unregisters its fFocusHelper. Perhaps that can be remedied by wrapping the
> call to handleSetData() in CompletionProposalPopup's SetData listener in a
> try/catch block, catching RuntimeException and invoking hide() before
> rethrowing the exception?

I filed bug 429925: "Protect against poorly behaved completion proposers" with a suggested patch for the second issue.
Comment 10 Noopur Gupta CLA 2014-04-16 12:03:57 EDT
*** Bug 432941 has been marked as a duplicate of this bug. ***
Comment 11 Jay Arthanareeswaran CLA 2014-05-05 01:15:45 EDT
Looks like this has always been around and not sure if we have the time to take this up for Luna. Moving to 4.5.
Comment 12 Terry Parker CLA 2014-05-06 18:58:54 EDT
(In reply to Jayaprakash Arthanareeswaran from comment #11)
> Looks like this has always been around and not sure if we have the time to
> take this up for Luna. Moving to 4.5.

I pushed up a patch for review at: https://git.eclipse.org/r/#/c/26082
Comment 13 Dani Megert CLA 2014-05-07 03:29:41 EDT
Jay, please take a look at the patch during RC1.
Comment 14 Jay Arthanareeswaran CLA 2014-05-08 06:48:08 EDT
Patch looks good. One issue I found is, I can trick the code into failing by having something like this for the annotation value:

value="test)>filter<("

But I think the odds of someone using such code is very little.
Comment 15 Jay Arthanareeswaran CLA 2014-05-09 06:30:22 EDT
Thanks Manoj, the fix is in master now:

http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=1d3546ae21ffe0ff967875f1cabb468e47817326
Comment 16 Terry Parker CLA 2014-05-09 12:41:19 EDT
(In reply to Jayaprakash Arthanareeswaran from comment #15)
> Thanks Manoj, the fix is in master now:
> 
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=1d3546ae21ffe0ff967875f1cabb468e47817326

Thanks for the review, Jay.
Comment 17 Manoj N Palat CLA 2014-05-19 05:01:27 EDT
Verified for Luna 4.4 RC1 Build id: I20140518-2000