Bug 509914 - [content assist] CompletionProposalComparator#compare may produce wrong results due to overflow/underflow
Summary: [content assist] CompletionProposalComparator#compare may produce wrong resul...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: investigate
Depends on:
Blocks:
 
Reported: 2017-01-04 04:47 EST by Andreas Sewe CLA
Modified: 2023-10-23 11:00 EDT (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-01-04 04:47:49 EST
While adding an IJavaCompletionProposal of my own I discovered an issue with org.eclipse.jdt.ui.text.java.CompletionProposalComparator#compare.

I want my proposal to show up below the "normal" Java and spelling-correction proposals but above the spelling-correction "meta-proposals" like 'disable spell checking', 'add word', etc.

I hence picked a relevance of IProposalRelevance.DISABLE_SPELL_CHECKING + 1. Unfortunately, this sometimes causes my proposal to be shown *above* the normal Java proposals and sometimes below. The problem is this snippet from CompletionProposalComparator#compare:

	int r1= getRelevance(p1);
	int r2= getRelevance(p2);
	int relevanceDif= r2 - r1;
	if (relevanceDif != 0) {
		return relevanceDif;
	}

Taking the difference is prone to overflow/underflow. The implementation should probably just use Integer#compare (available since Java 1.7).

I think this issue went unnoticed because Java and spelling-correction proposals are normally not shown simultaneously, but that's just a guess.

Also, the Javadoc of IJavaCompletionProposal#getRelevance really should not advocate an interval of [0, 1000] anymore as JDT itself doesn't adhere to it anymore (cf. IProposalRelevance's constants).
Comment 1 Eclipse Genie CLA 2019-10-01 18:40:27 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 2 Eclipse Genie CLA 2021-11-01 13:06:33 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 3 Eclipse Genie CLA 2021-11-01 13:06:38 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 4 Eclipse Genie CLA 2021-11-01 13:21:37 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 5 Eclipse Genie CLA 2021-11-01 13:21:47 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 6 Eclipse Genie CLA 2023-10-23 11:00:38 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.