| Summary: | ISystemViewElementAdapter.getAbsoluteName() must be clearly documented | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Tools] Target Management | Reporter: | Uwe Stieber <uwe.st> | ||||||
| Component: | RSE | Assignee: | Martin Oberhuber <mober.at+eclipse> | ||||||
| Status: | RESOLVED FIXED | QA Contact: | Martin Oberhuber <mober.at+eclipse> | ||||||
| Severity: | normal | ||||||||
| Priority: | P3 | CC: | ddykstal.eclipse, dmcknigh, martin.gutschelhofer, tobias.schwarz | ||||||
| Version: | 2.0 | ||||||||
| Target Milestone: | 2.0 | ||||||||
| Hardware: | PC | ||||||||
| OS: | Windows XP | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
|
Description
Uwe Stieber
Created attachment 63833 [details]
Patch removing the return of the element adapters hashcode
Committers: Discussion is open.
Attached patch
- reformated the IElementComparer for better readablitly,
- Added (commented out) tracing from tracking down problems in here
- Removed the "return indent.hashCode()" in order to fallback to the elements own hashcode calculation method.
One manifestation of the problem can be NPE's like the following: Caused by: java.lang.NullPointerException at org.eclipse.jface.viewers.TreeViewer.getParentItem(TreeViewer.java:216) at org.eclipse.rse.internal.ui.view.SafeTreeViewer.getParentItem(SafeTreeViewer.java:159) at org.eclipse.rse.internal.ui.view.SystemView.refreshAll(SystemView.java:3123) at org.eclipse.rse.internal.ui.view.SystemView$ResourceChangedJob.runInUIThread(SystemView.java:1942) at org.eclipse.ui.progress.UIJob$1.run(UIJob.java:94) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123) ... 56 more I have not yet read the code, but something sounds odd. Hashcodes should, in general, not be identical for different items if it can be helped. That's just good practice and a fix is warranted in this case. But hashcodes are not guaranteed to be unique. If code is written to assume that two objects are identical if they have the same hash then that code is wrong. Dave is right -- different elements may return the same hashCode although this leads to bad performance. The same element, however, may never return different hashCodes. From this perspective, the idea of the patch looks good since it may improve performance. The really important point in this bug though is, that ISystemViewElementAdapter.getAbsoluteName() must be clearly documented. Thus, changed the bug summary accordingly. (old value: The SystemView's IElementComparer may return same hashcode for different model objects) The SystemView makes so much use of getAbsoluteName() in such important places, that it is critical for extenders to properly implement the getAbsoluteName() API. Especially, it needs to be clarified whether getAbsoluteName() is allowed to return null or not. The code in the ElementComparer's equals() method seems to indicate that this is not allowed (NullPointerException is possible if 1st element returns null absolute name). The whole story, purpose, meaning and constraints of getAbsoluteName() need to be clearly documented. Perhaps AbstractSystemViewElementAdapter.getAbsoluteName() needs to be removed to make it abstract and force extenders to implement it. The changes made by the patch are hard to understand due to the beautification. The SystemView's ElementComparer should probably be put into a separate file instead. The important change is just in one line. Under the assumption that getAbsoluteName() must not ever return null, the patch is even invalid. Created attachment 63902 [details]
Updated patch more clearly showing the critical point
This updated patch is reduced to the important line in order to more clearly show its intention.
Wrote up documentation in IRemoteObjectIdentifier IRemoteObjectResolver and made sure that all actual implementations of the methods either have no Javadoc at all or reference the original Javadoc from these two classes. While working on the documentation, I found a need to clearly specify what kinds of IDs should be considered reserved by RSE-internal objects such as filter references - created bug 183965 to track this issue. Note that API Docs forbid getAbsoluteName() to return null and also explains why. I do think, however, that returning null may be valid under the following preconditions: 1. drag&drop, copy&paste are not supported by the subsystem for these elements 2. The elements never change, i.e. their hashCode() is always the same and can be used to uniquely identify the element (together with equals()) - this is important during refresh Because I think it should basically work, I don't want to add assertions checking for null into the code right now. We might add testcases for this at some time since working without absolute names may improve performance. But for now, extenders returning null are on their own due to the API docs and will not get any support. Committers please review my docs. [target cleanup] 2.0 M7 was the original target milestone for this bug |