Bug 528996 - org.eclipse.jdt.internal.core.SelectionRequestor may add "null" elements
Summary: org.eclipse.jdt.internal.core.SelectionRequestor may add "null" elements
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.8   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks: 528985
  Show dependency tree
 
Reported: 2017-12-20 04:31 EST by Andreas Sewe CLA
Modified: 2023-02-16 04:27 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-20 04:31:02 EST
We at Code Recommenders just got bitten (Bug 528985) by what I think is a bug in JDT (Photon M4):

We assume that SelectionRequestor.getElements() runs a zero-element array rather than a one-element array with a "null" entry when the selection could not be resolved. So far, this has been the case (Null Object pattern for the win). With a module selection, however, this assumption failed us.

IMHO, the following method in SelectionRequestor misses a null-check:

  @Override
  public void acceptModule(char[] moduleName, char[] uniqueKey, int start, int end) {
    IModuleDescription module = resolveModule(moduleName);
    addElement(module);
  }

AFAICT, all other calls to addElements in SelectionRequestor take great care not to pass a null argument.
Comment 1 Stephan Herrmann CLA 2017-12-20 08:08:31 EST
Makes sense.

Bonus question: would you be able to provide an example we could use for a JUnit test?

BTW: I guess when adding the null check we may also want to add the other stanza that other accept methods do: debug logging.
Comment 2 Andreas Sewe CLA 2017-12-20 08:30:34 EST
(In reply to Stephan Herrmann from comment #1)
> Makes sense.
> 
> Bonus question: would you be able to provide an example we could use for a
> JUnit test?

I'm afraid not, at least not easily: The code that trips over this is a listener on the current selection (Bug 528985 comment 1); in some cases the user clicks on a module declaration and the module cannot be resolved. Then, null gets inserted.

  module org.exam|ple { } // | denotes the cursor.

> BTW: I guess when adding the null check we may also want to add the other
> stanza that other accept methods do: debug logging.

Sounds good.
Comment 3 Manoj N Palat CLA 2018-05-17 03:25:08 EDT
bulk move out of 4.8
Comment 4 Manoj N Palat CLA 2018-08-16 00:09:11 EDT
Bulk move out of 4.9
Comment 5 Eclipse Genie CLA 2023-02-16 04:27:31 EST
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.