Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 528954 - [9] CompletionProposalCollector.getDeclaringType() fails assertion for MODULE_DECLARATION proposal
Summary: [9] CompletionProposalCollector.getDeclaringType() fails assertion for MODULE...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.8   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.7.3   Edit
Assignee: Noopur Gupta CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 528981
  Show dependency tree
 
Reported: 2017-12-19 08:57 EST by Andreas Sewe CLA
Modified: 2018-02-08 06:32 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Sewe CLA 2017-12-19 08:57:25 EST
If I read the Javadoc of CompletionProposalCollector.getDeclaringType(CompletionProposal) right, then this method should never fail its assertion but simply return null of the proposal doesn't have a declaring type:

 * Returns the type signature of the declaring type of a
 * <code>CompletionProposal</code>, or <code>null</code> for proposals
 * that do not have a declaring type. The return value is <em>not</em>
 * <code>null</code> for proposals of the following kinds:

This is not true for MODULE_DECLARATION proposals (we have a code path in Code Recommenders' that performs such a call). Also, the comment seems out of datr w.r.t. the list of proposals that apparently have a declaring type (MODULE_REF, PACKAGE_REF? Really?).

FWIW, here's a stacktrace I came across while fixing Bug 528901:

org.eclipse.core.runtime.AssertionFailedException: assertion failed: 
	at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
	at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
	at org.eclipse.jdt.ui.text.java.CompletionProposalCollector.getDeclaringType(CompletionProposalCollector.java:609)
	at org.eclipse.jdt.ui.text.java.CompletionProposalCollector.isFiltered(CompletionProposalCollector.java:547)
	at org.eclipse.jdt.ui.text.java.CompletionProposalCollector.accept(CompletionProposalCollector.java:244)
	at org.eclipse.recommenders.completion.rcp.processable.ProposalCollectingCompletionRequestor.createJdtProposals(ProposalCollectingCompletionRequestor.java:290)
	at org.eclipse.recommenders.completion.rcp.processable.ProposalCollectingCompletionRequestor.accept(ProposalCollectingCompletionRequestor.java:264)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.findModuleName(CompletionEngine.java:10696)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete(CompletionEngine.java:2052)
	at org.eclipse.jdt.internal.core.Openable.codeComplete(Openable.java:131)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:358)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:346)
	at org.eclipse.recommenders.internal.subwords.rcp.SubwordsSessionProcessor.computeProposals(SubwordsSessionProcessor.java:341)
	at org.eclipse.recommenders.internal.subwords.rcp.SubwordsSessionProcessor.getNewProposals(SubwordsSessionProcessor.java:228)
	at org.eclipse.recommenders.internal.subwords.rcp.SubwordsSessionProcessor.initializeContext(SubwordsSessionProcessor.java:168)
	at org.eclipse.recommenders.completion.rcp.processable.IntelligentCompletionProposalComputer.fireInitializeContext(IntelligentCompletionProposalComputer.java:293)
	at org.eclipse.recommenders.completion.rcp.processable.IntelligentCompletionProposalComputer.computeCompletionProposals(IntelligentCompletionProposalComputer.java:170)
	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerDescriptor.computeCompletionProposals(CompletionProposalComputerDescriptor.java:333)
	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory.computeCompletionProposals(CompletionProposalCategory.java:337)
	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.collectProposals(ContentAssistProcessor.java:331)
	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.computeCompletionProposals(ContentAssistProcessor.java:288)
Comment 1 Dani Megert CLA 2017-12-19 09:03:57 EST
Something looks fishy here indeed.

Noopur, please take a look for 4.7.3.
Comment 2 Noopur Gupta CLA 2017-12-19 09:42:14 EST
(In reply to Andreas Sewe from comment #0)
> This is not true for MODULE_DECLARATION proposals

MODULE_DECLARATION is not handled and should be added in #getDeclaringType to return null.

> Also, the comment seems out
> of datr w.r.t. the list of proposals that apparently have a declaring type
> (MODULE_REF, PACKAGE_REF? Really?).

For PACKAGE_REF, the Javadoc clearly mentions that it returns the package name instead of a type i.e. PACKAGE_REF (returns the package, but no type).

The Javadoc should be updated in a similar way for MODULE_REF also.

I think these two should cover the requirements of this bug report. Andreas, let me know if I missed something.
Comment 3 Andreas Sewe CLA 2017-12-19 09:50:26 EST
(In reply to Noopur Gupta from comment #2)
> (In reply to Andreas Sewe from comment #0)
> > This is not true for MODULE_DECLARATION proposals
> 
> MODULE_DECLARATION is not handled and should be added in #getDeclaringType
> to return null.
> 
> > Also, the comment seems out
> > of datr w.r.t. the list of proposals that apparently have a declaring type
> > (MODULE_REF, PACKAGE_REF? Really?).
> 
> For PACKAGE_REF, the Javadoc clearly mentions that it returns the package
> name instead of a type i.e. PACKAGE_REF (returns the package, but no type).
> 
> The Javadoc should be updated in a similar way for MODULE_REF also.
> 
> I think these two should cover the requirements of this bug report. Andreas,
> let me know if I missed something.

No, that sounds about right. However, if MODULE_REF returns type package (like PACKAGE_REF, which is indeed in the Javadoc), then shouldn't this be the case for MODULE_DECLARATION as well?

That being said, the most important thing for Code Recommenders is that we can CompletionProposalCollector.accept(CompletionProposal) with any proposal kind; we don't do anything module-declaration specific.
Comment 4 Noopur Gupta CLA 2017-12-19 11:19:54 EST
(In reply to Andreas Sewe from comment #3)
> However, if MODULE_REF returns type package
> (like PACKAGE_REF, which is indeed in the Javadoc), then shouldn't this be
> the case for MODULE_DECLARATION as well?

That's correct. However, I don't see any mention of MODULE_DECLARATION in org.eclipse.jdt.core.CompletionProposal.getDeclarationSignature() or any other proposal API from JDT Core. Hence, I will return null from #getDeclaringType for now and I will open a bug in JDT Core to provide the module declaration name from the proposal.
Comment 5 Eclipse Genie CLA 2017-12-19 11:28:52 EST
New Gerrit change created: https://git.eclipse.org/r/114430
Comment 6 Noopur Gupta CLA 2017-12-19 11:38:32 EST
(In reply to Noopur Gupta from comment #4)
> (In reply to Andreas Sewe from comment #3)
> > However, if MODULE_REF returns type package
> > (like PACKAGE_REF, which is indeed in the Javadoc), then shouldn't this be
> > the case for MODULE_DECLARATION as well?
> 
> That's correct. However, I don't see any mention of MODULE_DECLARATION in
> org.eclipse.jdt.core.CompletionProposal.getDeclarationSignature() or any
> other proposal API from JDT Core. Hence, I will return null from
> #getDeclaringType for now and I will open a bug in JDT Core to provide the
> module declaration name from the proposal.
Bug 528967 will handle this.
Comment 8 Eclipse Genie CLA 2017-12-22 06:33:59 EST
New Gerrit change created: https://git.eclipse.org/r/114662
Comment 9 Eclipse Genie CLA 2017-12-22 06:34:41 EST
Gerrit change https://git.eclipse.org/r/114662 was merged to [R4_7_maintenance].
Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=f8152711dae1b8f2f76144c336df5278ff98b9c6
Comment 10 Noopur Gupta CLA 2017-12-22 06:42:01 EST
Merged the fix for 4.7.3 and updated the bundle version:
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?h=R4_7_maintenance&id=fde01078ddd0d9679c8b6e9b59b3e90d20ecb30e
Comment 11 Noopur Gupta CLA 2018-01-25 02:11:57 EST
Verified for M5 in I20180124-2000.
Comment 12 Noopur Gupta CLA 2018-02-08 06:32:24 EST
Verified for 4.7.3 in M20180207-1700.