Bug 159932 - [content type] IContentType.isKindOf returns false even though argument is target's base type
Summary: [content type] IContentType.isKindOf returns false even though argument is ta...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-Resources-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-05 16:19 EDT by Peter Nehrer CLA
Modified: 2019-09-06 15:32 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 Peter Nehrer CLA 2006-10-05 16:19:20 EDT
This might not be a bug, maybe just incorrect usage on my part.

I try to obtain a matcher using a custom selection policy:

IContentTypeMatcher matcher = contentTypeManager.getMatcher(new MySelectionPolicy(), null);

This selection policy only allows content types that inherit from a certain fixed base type. So I obtain the base type:

IContentType baseType = contentTypeManager.getContentType("my.content.type");

In the seletion policy, I try to determine if the candidate "isKindOf" the base type:

public IContentType[] select(IContentType[] candidates, boolean fileName, boolean content) {
...
	if (candidates[i].isKindOf(baseType))
...

The problem is, I always get "false", even for types that clearly inherit from the base type (even the base type itself).

The problem seems to be in ContentType.isKindOf method: the candidate's dynamic type is "ContentType", but baseType is "ContentTypeHandler". ContentType.isKindOf uses reference equality for comparison (rather than comparing the ids, for example).

ContentTypeHandler.isKindOf first unwraps the target (ContentType), so that should work.

My question is, should they be symmetrical, or am I using it wrong?
Comment 1 Rafael Chaves CLA 2006-10-05 17:45:03 EDT
It is a bug indeed. The idea was that client code would never be given instances of ContentType, only ContentTypeHandlers (to avoid leaks in the case a new content type catalog is built). ISelectionPolicy is clearly a case where this rule was broken. It was never noticed before because the only implementation we had in the platform (in the resources plug-in) didn't call isKindOf. 

I would say it would be ok if the content type manager kept passing in instances of ContentType because selection policies are unlikely to hold them (ISelectionPolicy is more of a SPI than a regular API). Then, changing ContentType.isKindOf to only check the id should be enough to fix this problem.
Comment 2 John Arthorne CLA 2007-04-30 11:45:27 EDT
Clearing target milestone because it is milestone week and nobody has signed up to fix this.
Comment 3 Eclipse Webmaster CLA 2019-09-06 15:32:13 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.