Bug 427423 - [1.8][quick fix][null] Provide quick fixes for the new problem id's introduced for null analysis
Summary: [1.8][quick fix][null] Provide quick fixes for the new problem id's introduce...
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on: 440306
Blocks:
  Show dependency tree
 
Reported: 2014-02-04 19:42 EST by Martin Mathew CLA
Modified: 2022-08-30 17:07 EDT (History)
1 user (show)

See Also:


Attachments
Testcase provided by Stephan. (74.00 KB, application/octet-stream)
2014-02-04 19:42 EST, Martin Mathew CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Mathew CLA 2014-02-04 19:42:34 EST
Created attachment 239644 [details]
Testcase provided by Stephan.

Attached is the test case for the quick fixes UI has to support, make sure all test passes when this issue is fixed.
Comment 1 Stephan Herrmann CLA 2014-02-23 12:49:28 EST
I'd like to resolve this before GA, but the interface between Core and UI deserves discussion.

Consider these examples:

public class QF {
    void m(@NonNull Map<@NonNull String, @Nullable Object> map) { }
    void test1(@NonNull HashMap<String, @Nullable Object> map1) {
        m(map1);
    }
    void test2(HashMap<@NonNull String, @Nullable Object> map2) {
        m(map2); 
    }
}

Currently both calls to m() trigger the same IProblem.NullityUncheckedTypeAnnotationDetail
spelled out like this (first call):

"Null type safety (type annotations): The expression of type '@NonNull HashMap<String,@Nullable Object>' needs unchecked conversion to conform to '@NonNull Map<@NonNull String,@Nullable Object>'"

The question is: how does the QuickFix know where to add/remove the annotation(s)? In test1 the mismatch concerns a type argument, in test2 it's the main type.


I think the coolest solution would be:
- compiler attaches an annotated TypeBinding representing the "suggested" type"
- quickfix compares the suggested type to the actual type and updates annotations to make both match.

I wouldn't burden UI with computing the "suggested type", because that can be tricky to determine, as illustrated here:

class StringKeyedMap<T> extends HashMap<@NonNull String,T> { }
class QF2 {
	void m(@NonNull Map<@NonNull String, @Nullable Object> map) { }
	void test3() {
		@NonNull StringKeyedMap<Object> map3 = new StringKeyedMap<>();
		m(map3);
	}
}

Here we have a mismatch between:
 - provided: @NonNull StringKeyedMap<Object>
 - required: @NonNull Map<@NonNull String,@Nullable Object>
How do we make the connection between type parameters of different types?

The compiler has the machinery for this kind of analysis, so it can provide actually two "suggested types":
- either correct the provided to '@NonNull StringKeyedMap<@Nullable Object>'
- or correct the required to '@NonNull Map<@NonNull String,Object>'

Now for the interface: I could tweak two compiler TypeBindings into the DefaultProblem. Question: Is JDT/UI comfortable with extracting information from these two compiler internal classes?

I probably cannot offer anything public, because the compiler cannot use dom bindings or such.

Any ideas? Some public bridge in the dom package that holds a BindingResolver, and when given a DefaultProblem/IProblem it will answer the contained bindings translated into dom bindings?

---

If this approach doesn't fly, we'd have to design some new "path" abstraction, (like in type annotation class file representation) pointing to the location(s) needing an annotation update.
Comment 2 Stephan Herrmann CLA 2014-07-24 06:02:34 EDT
See also bug 440306.
Comment 3 Stephan Herrmann CLA 2015-02-26 07:15:13 EST
Bug 458186 comment 4 contains a small step in this direction.
Comment 4 Stephan Herrmann CLA 2017-05-16 12:05:36 EDT
Ran out of time for 4.7. Bulk move to 4.8.
Comment 5 Stephan Herrmann CLA 2018-03-08 18:28:57 EST
Not sure there's any low hanging fruit remaining in this area.
Comment 6 Stephan Herrmann CLA 2020-06-10 03:34:59 EDT
.
Comment 7 Eclipse Genie CLA 2022-08-30 17:07:50 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.