Bug 544388 - BinaryMethod.getParameterNames fails on javadoc with annotated parameters
Summary: BinaryMethod.getParameterNames fails on javadoc with annotated parameters
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.10   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact: Jay Arthanareeswaran CLA
URL:
Whiteboard: stalebug bulk move
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-12 11:41 EST by Eric Milles CLA
Modified: 2023-08-10 19:02 EDT (History)
3 users (show)

See Also:


Attachments
Parse names from dl html (24.92 KB, text/plain)
2019-02-12 15:48 EST, Eric Milles CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Milles CLA 2019-02-12 11:41:15 EST
When processing a method for content assist, an AIOOBE is thrown from InternalCompletionProposal [1].  This is happening because BinaryMethod.getParameterNames() for the method "io.toro.integrate.CacheMethods#cacheGet" [2] has annotations on its parameters.

BinaryMethod circa line 385 is trying to find the begin and end parenthesis of the method doc.  It properly skips over method annotations to find the left paren.  However "final int indexOfClosingParen = methodDoc.indexOf(')', indexOfOpenParen);" gets the index of the right paren of the first parameter type annotation.  Thus it ends up with paramsSource as "@GloopParameter(value="Cache name in the current package",allowNull=false".

There are more details described at [1], including a simple .classpath that can be used to recreate.


[1] https://github.com/groovy/groovy-eclipse/issues/808
[2] https://javadocs.torocloud.com/integrate/3.2.0/io/toro/integrate/CacheMethods.html#cacheGet-java.lang.String-java.util.Collection-
Comment 1 Eric Milles CLA 2019-02-12 15:48:55 EST
Created attachment 277547 [details]
Parse names from dl html

If parameter names are commonly provided as part of <dl>...<dd><code>name</code>...</dd></dl> markup, this could be easier than trying to deal with annotations.
Comment 2 Eric Milles CLA 2019-02-14 11:13:54 EST
Here is an updated patch section that reads from the method signature text instead of the parameters table.  Ex "<pre>public static&nbsp;<a href="http://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>[]&nbsp;tokenizeToStringArray(<a href="http://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;str,
                                             <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;delimiter,
                                             boolean&nbsp;trimTokens,
                                             boolean&nbsp;ignoreEmptyTokens,
                                             boolean&nbsp;retainDelimeter)</pre>"



		if (methodDoc != null) {
			// GROOVY add
			int indexOfPre = methodDoc.indexOf("<pre>"); //$NON-NLS-1$
			if (indexOfPre != -1) { List<String> names = new ArrayList<>();
				String methodSig = methodDoc.substring(indexOfPre, methodDoc.indexOf("</pre>", indexOfPre) + 6); //$NON-NLS-1$
				Matcher matcher = Pattern.compile("&nbsp;(\\p{javaJavaIdentifierPart}+)[,)]").matcher(methodSig); //$NON-NLS-1$
				while (matcher.find()) {
					names.add(matcher.group(1));
				}
				if (this.parameterTypes.length == names.size()) {
					return this.parameterNames = names.toArray(new String[names.size()]);
				} else {
					System.err.print(""); //$NON-NLS-1$
				}
			}
			// GROOVY end
			int indexOfOpenParen = methodDoc.indexOf('(');
Comment 3 Jay Arthanareeswaran CLA 2019-02-18 01:24:05 EST
Eric,

We will consider this for 4.12. I haven't looked at the proposed fix yet, though.
Comment 4 Manoj N Palat CLA 2019-08-27 01:07:25 EDT
Bulk move to 4.14
Comment 5 Manoj N Palat CLA 2019-08-27 02:06:33 EDT
Bulk move out of 4.13
Comment 6 Eclipse Genie CLA 2021-08-19 19:10:51 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.

If you have further information on the current state of the bug, please add it. 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.
Comment 7 Eclipse Genie CLA 2023-08-10 19:02:57 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.

If you have further information on the current state of the bug, please add it. 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.